mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 22:03:43 +01:00
doc : split c++ code from rst
- examples split from the rst file using a python script (split_code). - Final result for the doc is unchanged. - examples are compiled and tested with the other tests. - examples' code have been clang-formatted, with triqs style. - doc compiles much faster, and with the same options as the rest of the test. - examples are added as tests, so they are run by make test, as simple C tests. - done for the tutorials and the reference. - autocompile removed (changed into triqs_example directive). - add triqs_example : - make a literal include of the source code. - runs the compiled example - add, as before, the result to the source code in the doc. - added the script split_code, used to make the changes automatically, maybe for later reuse. (in _tools)
This commit is contained in:
parent
4f51c1e043
commit
3fe400d34c
@ -19,49 +19,9 @@ else (Sphinx_Math_Generator_MathJax)
|
|||||||
endif (Sphinx_Math_Generator_MathJax)
|
endif (Sphinx_Math_Generator_MathJax)
|
||||||
|
|
||||||
# the local extensions....
|
# 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
|
#EXECUTE_PROCESS(COMMAND sh -c "ln -sf ${CMAKE_BINARY_DIR}/triqs/libtriqs.so ${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
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)
|
|
||||||
|
|
||||||
# Generate the conf.py
|
# Generate the conf.py
|
||||||
FILE(GLOB_RECURSE SOURCES *.rst)
|
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})
|
set(DOC_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
include(${TRIQS_SOURCE_DIR}/cmake/BuildSphinx.cmake)
|
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
|
# Set dependencies
|
||||||
GET_PROPERTY(PYTHON_DYNAMIC_MODULES_LIST GLOBAL PROPERTY PYTHON_DYNAMIC_MODULES_LIST)
|
GET_PROPERTY(PYTHON_DYNAMIC_MODULES_LIST GLOBAL PROPERTY PYTHON_DYNAMIC_MODULES_LIST)
|
||||||
foreach (mod ${PYTHON_DYNAMIC_MODULES_LIST})
|
foreach (mod ${PYTHON_DYNAMIC_MODULES_LIST})
|
||||||
|
49
doc/_tools/split_code.py
Normal file
49
doc/_tools/split_code.py
Normal file
@ -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
|
@ -22,7 +22,7 @@ import sys, os
|
|||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
sys.path +=[ #"@CMAKE_BINARY_DIR@/doc/breathe",
|
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"]
|
"@CMAKE_BINARY_DIR@/doc/sandbox","@CMAKE_BINARY_DIR@/doc"]
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||||
@ -40,15 +40,7 @@ extensions += [
|
|||||||
# 'inheritance_diagram',
|
# 'inheritance_diagram',
|
||||||
'numpydoc']
|
'numpydoc']
|
||||||
|
|
||||||
extensions += ['autocompile','autorun']
|
extensions += ['autorun', 'triqs_example']
|
||||||
|
|
||||||
##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(';')] )
|
|
||||||
)
|
|
||||||
|
|
||||||
##options for autorun module: python execution
|
##options for autorun module: python execution
|
||||||
autorun_languages = {}
|
autorun_languages = {}
|
||||||
|
209
doc/overview.rst
209
doc/overview.rst
@ -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 <link>
|
|
||||||
|
|
||||||
Solvers for impurity models
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
TRIQS comes with powerful numerical solvers for quantum impurity models.
|
|
||||||
|
|
||||||
|
|
||||||
[example here]
|
|
||||||
|
|
||||||
To learn more, see <link>
|
|
||||||
|
|
||||||
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 <link>
|
|
||||||
|
|
||||||
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 <link>
|
|
||||||
|
|
||||||
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 <iostream>
|
|
||||||
#include <triqs/utility/callbacks.hpp>
|
|
||||||
#include <triqs/mc_tools/mc_generic.hpp>
|
|
||||||
|
|
||||||
// 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<double>(), 0);
|
|
||||||
boost::mpi::reduce(c, M, sum_M, std::plus<double>(), 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<double> 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 <link>
|
|
||||||
|
|
||||||
Array library
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
Create, manipulate and store powerful multi-dimensional arrays:
|
|
||||||
|
|
||||||
|
|
||||||
.. highlight:: c
|
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array;
|
|
||||||
int main(){
|
|
||||||
array<double,1> A(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
To learn more, see <link>
|
|
||||||
|
|
||||||
Expression library: CLEF
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
Write mathematical expressions in a seamless and computationally efficient way:
|
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
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 <link>
|
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
add_all_subdirectories_with_cmakelist()
|
add_all_subdirectories_with_cmakelist()
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,3 +8,7 @@ set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES
|
|||||||
#${TRIQS_SOURCE_DIR}/triqs/arrays/vector.hpp
|
#${TRIQS_SOURCE_DIR}/triqs/arrays/vector.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
all_tests()
|
||||||
|
add_subdirectory(containers)
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,26 +14,4 @@ MPI
|
|||||||
The `value classes` (array, matrix, vector) can be bcasted, reduced,
|
The `value classes` (array, matrix, vector) can be bcasted, reduced,
|
||||||
with the boost.mpi library, e.g. :
|
with the boost.mpi library, e.g. :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./IO_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <boost/mpi.hpp>
|
|
||||||
using triqs::arrays::array;using triqs::clef::placeholder;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
boost::mpi::environment env;//argc, argv);
|
|
||||||
boost::mpi::communicator world;
|
|
||||||
|
|
||||||
array<long,2> 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<array<long,2> >(),0);
|
|
||||||
|
|
||||||
int s= world.size();
|
|
||||||
if (world.rank() ==0) std::cout<<" C = "<<C<< " should be "<< array<long,2>( (s*(s+1)/2) * A) <<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
22
doc/reference/c++/arrays/IO_0.cpp
Normal file
22
doc/reference/c++/arrays/IO_0.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <boost/mpi.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
boost::mpi::environment env; // argc, argv);
|
||||||
|
boost::mpi::communicator world;
|
||||||
|
|
||||||
|
array<long, 2> 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<array<long, 2>>(), 0);
|
||||||
|
|
||||||
|
int s = world.size();
|
||||||
|
if (world.rank() == 0) std::cout << " C = " << C << " should be " << array<long, 2>((s * (s + 1) / 2) * A) << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -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.
|
This algebraic expressions can therefore be used in assignment array/matrix contructors.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./algebras_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::clef::placeholder;
|
|
||||||
int main() {
|
|
||||||
// init
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
array<long,2> A (2,2), B(2,2);
|
|
||||||
A(i_,j_) << i_ + j_ ;
|
|
||||||
B(i_,j_) << i_ - j_ ;
|
|
||||||
|
|
||||||
// use expressions
|
|
||||||
array<long,2> C = A+ 2*B;
|
|
||||||
array<double,2> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Arrays vs matrices
|
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.
|
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 :
|
However, you can always use e.g. `matrix_view` from a array of rank 2 :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./algebras_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main() {
|
|
||||||
array<long,2> A(2,2); matrix<long,2> M(2,2);
|
|
||||||
//M + A; // --> ERROR. Rejected by the compiler.
|
|
||||||
M + make_matrix_view(A); //--> OK.
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Making such a view is very cheap, it only copies the index systems. Nevertheless
|
Making such a view is very cheap, it only copies the index systems. Nevertheless
|
||||||
|
20
doc/reference/c++/arrays/algebras_0.cpp
Normal file
20
doc/reference/c++/arrays/algebras_0.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
// init
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
array<long, 2> A(2, 2), B(2, 2);
|
||||||
|
A(i_, j_) << i_ + j_;
|
||||||
|
B(i_, j_) << i_ - j_;
|
||||||
|
|
||||||
|
// use expressions
|
||||||
|
array<long, 2> C = A + 2 * B;
|
||||||
|
array<double, 2> 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;
|
||||||
|
}
|
||||||
|
|
9
doc/reference/c++/arrays/algebras_1.cpp
Normal file
9
doc/reference/c++/arrays/algebras_1.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
array<long, 2> A(2, 2);
|
||||||
|
matrix<long, 2> M(2, 2);
|
||||||
|
// M + A; // --> ERROR. Rejected by the compiler.
|
||||||
|
M + make_matrix_view(A); //--> OK.
|
||||||
|
}
|
||||||
|
|
@ -25,19 +25,7 @@ The * operator map the matrix x matrix and matrix x vector product.
|
|||||||
|
|
||||||
Example : matrix * matrix and * vector ...
|
Example : matrix * matrix and * vector ...
|
||||||
|
|
||||||
..
|
.. triqs_example:: ./blas_lapack_0.cpp
|
||||||
compileblock::
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::matrix; using triqs::clef::placeholder;
|
|
||||||
int main() {
|
|
||||||
// declare an init 2 matrices
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
matrix<double> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
For types that lapack do not use, a generic version of the matrix product is provided.
|
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).
|
(same syntax, the dispatch is made at compile time depending of the type of the matrices).
|
||||||
|
|
||||||
|
14
doc/reference/c++/arrays/blas_lapack_0.cpp
Normal file
14
doc/reference/c++/arrays/blas_lapack_0.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::matrix;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
// declare an init 2 matrices
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
matrix<double> 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;
|
||||||
|
}
|
||||||
|
|
@ -186,46 +186,7 @@ For example:
|
|||||||
|
|
||||||
* A simple solution :
|
* A simple solution :
|
||||||
|
|
||||||
.. compileblock ::
|
.. triqs_example:: ./concepts_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
namespace triqs { namespace arrays { // better to put it in this namespace for ADL...
|
|
||||||
|
|
||||||
template<typename T> class immutable_diagonal_matrix_view {
|
|
||||||
|
|
||||||
array_view<T,1> data; // the diagonal stored as a 1d array
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
immutable_diagonal_matrix_view(array_view<T,1> 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<typename T> struct ImmutableMatrix<immutable_diagonal_matrix_view<T>> : std::true_type{};
|
|
||||||
}}
|
|
||||||
|
|
||||||
/// TESTING
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
auto a = array<int,1> {1,2,3,4};
|
|
||||||
auto d = immutable_diagonal_matrix_view<int>{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<int>(d*d) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
* Discussion
|
* Discussion
|
||||||
|
|
||||||
* Of course, this solution is not perfect. Several algorithms could be optimised if we know that a matrix is diagonal.
|
* Of course, this solution is not perfect. Several algorithms could be optimised if we know that a matrix is diagonal.
|
||||||
|
42
doc/reference/c++/arrays/concepts_0.cpp
Normal file
42
doc/reference/c++/arrays/concepts_0.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
namespace triqs {
|
||||||
|
namespace arrays { // better to put it in this namespace for ADL...
|
||||||
|
|
||||||
|
template <typename T> class immutable_diagonal_matrix_view {
|
||||||
|
|
||||||
|
array_view<T, 1> data; // the diagonal stored as a 1d array
|
||||||
|
|
||||||
|
public:
|
||||||
|
immutable_diagonal_matrix_view(array_view<T, 1> 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 <typename T> struct ImmutableMatrix<immutable_diagonal_matrix_view<T>> : std::true_type {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TESTING
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
auto a = array<int, 1>{1, 2, 3, 4};
|
||||||
|
auto d = immutable_diagonal_matrix_view<int>{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<int>(d * d) << std::endl;
|
||||||
|
}
|
||||||
|
|
3
doc/reference/c++/arrays/containers/CMakeLists.txt
Normal file
3
doc/reference/c++/arrays/containers/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
all_tests()
|
||||||
|
|
||||||
|
|
@ -22,46 +22,4 @@ Examples::
|
|||||||
Some examples of usage :
|
Some examples of usage :
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./STL_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <algorithm>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::matrix; using triqs::clef::placeholder;
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
// For example, one can make a vector of arrays ... ::
|
|
||||||
|
|
||||||
array<long,2> A (2,3);
|
|
||||||
std::vector<array<long,2> > VV;
|
|
||||||
VV.push_back(A);
|
|
||||||
|
|
||||||
// ... or a map ::
|
|
||||||
std::map<int, array<long,2> > 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<int> V (10,2);
|
|
||||||
array<int,1 > 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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
40
doc/reference/c++/arrays/containers/STL_0.cpp
Normal file
40
doc/reference/c++/arrays/containers/STL_0.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::matrix;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
// For example, one can make a vector of arrays ... ::
|
||||||
|
|
||||||
|
array<long, 2> A(2, 3);
|
||||||
|
std::vector<array<long, 2>> VV;
|
||||||
|
VV.push_back(A);
|
||||||
|
|
||||||
|
// ... or a map ::
|
||||||
|
std::map<int, array<long, 2>> 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<int> V(10, 2);
|
||||||
|
array<int, 1> 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;
|
||||||
|
}
|
||||||
|
|
@ -30,19 +30,7 @@ It must be called with exactly `rank` size_t (or it is a compile time error).
|
|||||||
Example
|
Example
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./call_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main(){
|
|
||||||
array<double,2> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Another ::
|
Another ::
|
||||||
|
|
||||||
A(1, range(0,2) ) // 1d slice
|
A(1, range(0,2) ) // 1d slice
|
||||||
@ -78,20 +66,7 @@ The return type of the () operator is :
|
|||||||
Example
|
Example
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./call_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main(){
|
|
||||||
array<double,2> 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<double,2> V = A(range(0,2), range(0,2));
|
|
||||||
std::cout <<"V = "<< V << std::endl;
|
|
||||||
V = -V;
|
|
||||||
std::cout <<"A = "<< A << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:hidden:
|
:hidden:
|
||||||
|
|
||||||
@ -117,22 +92,7 @@ Example
|
|||||||
|
|
||||||
* **Example** :
|
* **Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./call_2.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::clef::placeholder;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
array<double,2> A(2,2), B(2,2);
|
|
||||||
|
|
||||||
A(i_,j_) << i_ + 2*j_ ;
|
|
||||||
B(i_,j_) << A(j_,i_)/2;
|
|
||||||
|
|
||||||
std::cout << "A = "<<A << std::endl;
|
|
||||||
std::cout << "B = "<<B << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
The syntax uses a <<, not = since the array is not assigned to an expression
|
The syntax uses a <<, not = since the array is not assigned to an expression
|
||||||
but filled by the evaluation thereof.
|
but filled by the evaluation thereof.
|
||||||
|
10
doc/reference/c++/arrays/containers/call_0.cpp
Normal file
10
doc/reference/c++/arrays/containers/call_0.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
array<double, 2> 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;
|
||||||
|
}
|
||||||
|
|
12
doc/reference/c++/arrays/containers/call_1.cpp
Normal file
12
doc/reference/c++/arrays/containers/call_1.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
array<double, 2> 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<double, 2> V = A(range(0, 2), range(0, 2));
|
||||||
|
std::cout << "V = " << V << std::endl;
|
||||||
|
V = -V;
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
}
|
||||||
|
|
16
doc/reference/c++/arrays/containers/call_2.cpp
Normal file
16
doc/reference/c++/arrays/containers/call_2.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
array<double, 2> A(2, 2), B(2, 2);
|
||||||
|
|
||||||
|
A(i_, j_) << i_ + 2 * j_;
|
||||||
|
B(i_, j_) << A(j_, i_) / 2;
|
||||||
|
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
std::cout << "B = " << B << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -33,18 +33,7 @@ ellipsis
|
|||||||
|
|
||||||
* Example:
|
* Example:
|
||||||
|
|
||||||
.. compileblock ::
|
.. triqs_example:: ./range_ell_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::ellipsis;
|
|
||||||
int main(){
|
|
||||||
array<long,4> B(2,3,4,5) ;
|
|
||||||
B(0,ellipsis(),3) ; // same as B(0, range(),range(), 3 )
|
|
||||||
B(0,ellipsis(),2,3); // same as B(0, range(), 2, 3 )
|
|
||||||
B(ellipsis(),2,3) ; // same as B( range(),range(), 2, 3 )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
* NB : there can be at most one ellipsis per expression (otherwise it would be meaningless).
|
* NB : there can be at most one ellipsis per expression (otherwise it would be meaningless).
|
||||||
|
|
||||||
* Example of usage :
|
* Example of usage :
|
||||||
@ -52,25 +41,4 @@ ellipsis
|
|||||||
Ellipsis are useful to write generic algorithms. For example, imagine that you want to sum
|
Ellipsis are useful to write generic algorithms. For example, imagine that you want to sum
|
||||||
arrays on their first index :
|
arrays on their first index :
|
||||||
|
|
||||||
.. compileblock ::
|
.. triqs_example:: ./range_ell_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::ellipsis;
|
|
||||||
|
|
||||||
// a generic function that sum array, array_view or in fact anything
|
|
||||||
// with the right concept on its first dimension
|
|
||||||
template<typename ArrayType>
|
|
||||||
array<typename ArrayType::value_type, ArrayType::rank-1> sum0 (ArrayType const & A) {
|
|
||||||
array<typename ArrayType::value_type, ArrayType::rank-1> res = A(0,ellipsis());
|
|
||||||
for (size_t u =1; u< first_dim(A); ++u) res += A(u,ellipsis());
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// test
|
|
||||||
int main(){
|
|
||||||
array<double,2> A(5,2); A()=2;
|
|
||||||
array<double,3> B(5,2,3); B() = 1;
|
|
||||||
std::cout<< sum0(A) << sum0(B) <<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
10
doc/reference/c++/arrays/containers/range_ell_0.cpp
Normal file
10
doc/reference/c++/arrays/containers/range_ell_0.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::ellipsis;
|
||||||
|
int main() {
|
||||||
|
array<long, 4> B(2, 3, 4, 5);
|
||||||
|
B(0, ellipsis(), 3); // same as B(0, range(),range(), 3 )
|
||||||
|
B(0, ellipsis(), 2, 3); // same as B(0, range(), 2, 3 )
|
||||||
|
B(ellipsis(), 2, 3); // same as B( range(),range(), 2, 3 )
|
||||||
|
}
|
||||||
|
|
21
doc/reference/c++/arrays/containers/range_ell_1.cpp
Normal file
21
doc/reference/c++/arrays/containers/range_ell_1.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::ellipsis;
|
||||||
|
|
||||||
|
// a generic function that sum array, array_view or in fact anything
|
||||||
|
// with the right concept on its first dimension
|
||||||
|
template <typename ArrayType> array<typename ArrayType::value_type, ArrayType::rank - 1> sum0(ArrayType const& A) {
|
||||||
|
array<typename ArrayType::value_type, ArrayType::rank - 1> res = A(0, ellipsis());
|
||||||
|
for (size_t u = 1; u < first_dim(A); ++u) res += A(u, ellipsis());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// test
|
||||||
|
int main() {
|
||||||
|
array<double, 2> A(5, 2);
|
||||||
|
A() = 2;
|
||||||
|
array<double, 3> B(5, 2, 3);
|
||||||
|
B() = 1;
|
||||||
|
std::cout << sum0(A) << sum0(B) << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -82,37 +82,4 @@ vector(const T & X) Type T models the :ref:`ImmutableVec
|
|||||||
Examples
|
Examples
|
||||||
------------
|
------------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./reg_constructors_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::matrix;
|
|
||||||
using triqs::arrays::vector; using triqs::arrays::permutation;
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
// A 3d array of long, C ordering, no option
|
|
||||||
array<long, 3> A3(1,2,3);
|
|
||||||
|
|
||||||
// A 2d array of double, C ordering, with explicit Bound Checking
|
|
||||||
array<double, 2> B(1,2);
|
|
||||||
|
|
||||||
// a matrix of long
|
|
||||||
matrix<long> M(2,2);
|
|
||||||
|
|
||||||
// a vector of double
|
|
||||||
vector<double> V(10);
|
|
||||||
|
|
||||||
// arrays with custom TraversalOrder
|
|
||||||
|
|
||||||
// C-style
|
|
||||||
array<long, 3, 0, permutation(2,1,0)> A0(2,3,4);
|
|
||||||
array<long, 3, 0> A0b; // same type but empty
|
|
||||||
|
|
||||||
// Fortran-style
|
|
||||||
array<long, 3, TRAVERSAL_ORDER_FORTRAN> A4 (2,3,4);
|
|
||||||
array<long, 3, 0, permutation(0,1,2)> A1b; //same type but empty
|
|
||||||
|
|
||||||
// custom : (i,j,k) : index j is fastest, then k, then i
|
|
||||||
array<long, 3, 0, permutation(1,0,2)> A2(2,3,4);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
33
doc/reference/c++/arrays/containers/reg_constructors_0.cpp
Normal file
33
doc/reference/c++/arrays/containers/reg_constructors_0.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::matrix;
|
||||||
|
using triqs::arrays::vector;
|
||||||
|
using triqs::arrays::permutation;
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
// A 3d array of long, C ordering, no option
|
||||||
|
array<long, 3> A3(1, 2, 3);
|
||||||
|
|
||||||
|
// A 2d array of double, C ordering, with explicit Bound Checking
|
||||||
|
array<double, 2> B(1, 2);
|
||||||
|
|
||||||
|
// a matrix of long
|
||||||
|
matrix<long> M(2, 2);
|
||||||
|
|
||||||
|
// a vector of double
|
||||||
|
vector<double> V(10);
|
||||||
|
|
||||||
|
// arrays with custom TraversalOrder
|
||||||
|
|
||||||
|
// C-style
|
||||||
|
array<long, 3, 0, permutation(2, 1, 0)> A0(2, 3, 4);
|
||||||
|
array<long, 3, 0> A0b; // same type but empty
|
||||||
|
|
||||||
|
// Fortran-style
|
||||||
|
array<long, 3, TRAVERSAL_ORDER_FORTRAN> A4(2, 3, 4);
|
||||||
|
array<long, 3, 0, permutation(0, 1, 2)> A1b; // same type but empty
|
||||||
|
|
||||||
|
// custom : (i,j,k) : index j is fastest, then k, then i
|
||||||
|
array<long, 3, 0, permutation(1, 0, 2)> A2(2, 3, 4);
|
||||||
|
}
|
||||||
|
|
@ -16,21 +16,7 @@ resize
|
|||||||
|
|
||||||
* **Examples** :
|
* **Examples** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./resize_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main() {
|
|
||||||
array<double,2> A(2,3);
|
|
||||||
A.resize (make_shape (5,5));
|
|
||||||
|
|
||||||
matrix<double,2> M;
|
|
||||||
M.resize(3,3);
|
|
||||||
|
|
||||||
vector<double> V;
|
|
||||||
V.resize(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Views can not be resized.
|
Views can not be resized.
|
||||||
@ -46,18 +32,7 @@ resize
|
|||||||
|
|
||||||
Illustration :
|
Illustration :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./resize_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main() {
|
|
||||||
array<double,2> A(2,3); A()= 9;
|
|
||||||
array_view<double,2> V = A();
|
|
||||||
A.resize (make_shape (5,5)); A()=0;
|
|
||||||
std::cout<< V<< std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.. _arr_resize_ch:
|
.. _arr_resize_ch:
|
||||||
|
|
||||||
resize_or_check_if_view
|
resize_or_check_if_view
|
||||||
|
13
doc/reference/c++/arrays/containers/resize_0.cpp
Normal file
13
doc/reference/c++/arrays/containers/resize_0.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
array<double, 2> A(2, 3);
|
||||||
|
A.resize(make_shape(5, 5));
|
||||||
|
|
||||||
|
matrix<double, 2> M;
|
||||||
|
M.resize(3, 3);
|
||||||
|
|
||||||
|
vector<double> V;
|
||||||
|
V.resize(10);
|
||||||
|
}
|
||||||
|
|
11
doc/reference/c++/arrays/containers/resize_1.cpp
Normal file
11
doc/reference/c++/arrays/containers/resize_1.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
array<double, 2> A(2, 3);
|
||||||
|
A() = 9;
|
||||||
|
array_view<double, 2> V = A();
|
||||||
|
A.resize(make_shape(5, 5));
|
||||||
|
A() = 0;
|
||||||
|
std::cout << V << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -22,24 +22,7 @@ swap
|
|||||||
|
|
||||||
* **Example** :
|
* **Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./swap_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
using triqs::arrays::vector; using triqs::arrays::range;
|
|
||||||
int main () {
|
|
||||||
triqs::arrays::vector<double> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.. _arr_deep_swap:
|
.. _arr_deep_swap:
|
||||||
|
|
||||||
deep_swap
|
deep_swap
|
||||||
@ -54,23 +37,4 @@ deep_swap
|
|||||||
|
|
||||||
* **Example** (compare with swap) :
|
* **Example** (compare with swap) :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./swap_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
using triqs::arrays::vector; using triqs::arrays::range;
|
|
||||||
int main () {
|
|
||||||
triqs::arrays::vector<double> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
18
doc/reference/c++/arrays/containers/swap_0.cpp
Normal file
18
doc/reference/c++/arrays/containers/swap_0.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
using triqs::arrays::vector;
|
||||||
|
using triqs::arrays::range;
|
||||||
|
int main() {
|
||||||
|
triqs::arrays::vector<double> 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;
|
||||||
|
}
|
||||||
|
|
18
doc/reference/c++/arrays/containers/swap_1.cpp
Normal file
18
doc/reference/c++/arrays/containers/swap_1.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
using triqs::arrays::vector;
|
||||||
|
using triqs::arrays::range;
|
||||||
|
int main() {
|
||||||
|
triqs::arrays::vector<double> 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;
|
||||||
|
}
|
||||||
|
|
@ -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++,
|
will be thrown. It's .what() returns the file and line where the exception occurs, with the stack of all in C++,
|
||||||
e.g. :
|
e.g. :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./debug_0.cpp
|
||||||
|
|
||||||
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array;
|
|
||||||
int main(){
|
|
||||||
try {
|
|
||||||
array<double,2> 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.. note:: Bound Checking is not necessarly used for debugging. You may used it for a given array, catching exception.
|
.. 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.
|
Beware however that bound checking comes with some performance penalty.
|
||||||
|
|
||||||
|
15
doc/reference/c++/arrays/debug_0.cpp
Normal file
15
doc/reference/c++/arrays/debug_0.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
|
||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
int main() {
|
||||||
|
try {
|
||||||
|
array<double, 2> 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
|
||||||
|
}
|
||||||
|
|
@ -50,16 +50,7 @@ in the order specified by the TraversalOrder flag of the array.
|
|||||||
|
|
||||||
Example :
|
Example :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./foreach_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array;
|
|
||||||
int main(){
|
|
||||||
array<long,2> A (2,3);
|
|
||||||
foreach (A, [&A](size_t i, size_t j) { A(i,j) = i+j;});
|
|
||||||
std::cout<<" A "<< A << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
You *can* pass a std::function as Function, but it is not recommended in critical parts of the code.
|
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
|
* The for loop are automatically organised to optimize the traversal order of A
|
||||||
using the TraversalOrder flag of the array.
|
using the TraversalOrder flag of the array.
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./foreach_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array;
|
|
||||||
int main(){
|
|
||||||
array<long,2> A (2,3);
|
|
||||||
assign_foreach (A, [](size_t i, size_t j) { return i+j;});
|
|
||||||
std::cout<<" A "<< A << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Cf the note of the *foreach* function.
|
Cf the note of the *foreach* function.
|
||||||
|
8
doc/reference/c++/arrays/foreach_0.cpp
Normal file
8
doc/reference/c++/arrays/foreach_0.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
int main() {
|
||||||
|
array<long, 2> A(2, 3);
|
||||||
|
foreach(A, [&A](size_t i, size_t j) { A(i, j) = i + j; });
|
||||||
|
std::cout << " A " << A << std::endl;
|
||||||
|
}
|
||||||
|
|
8
doc/reference/c++/arrays/foreach_1.cpp
Normal file
8
doc/reference/c++/arrays/foreach_1.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
int main() {
|
||||||
|
array<long, 2> A(2, 3);
|
||||||
|
assign_foreach(A, [](size_t i, size_t j) { return i + j; });
|
||||||
|
std::cout << " A " << A << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -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
|
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 :
|
or any subgroup thereof. For example :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./h5_rw_0.cpp
|
||||||
|
.. triqs_example:: examples_code/h5_rw.cpp
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::matrix;
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
array<double,2> 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<double,2> B; // read the file into B
|
|
||||||
matrix<double> B; // read the file into B
|
|
||||||
h5_read (file, "A",B);
|
|
||||||
std::cout << "B = "<<B<<std::endl;
|
|
||||||
h5_write(file,"B",B);
|
|
||||||
}
|
|
||||||
|
|
||||||
.. literalinclude:: examples_code/h5_rw.cpp
|
|
||||||
|
|
||||||
Note that :
|
Note that :
|
||||||
|
|
||||||
|
18
doc/reference/c++/arrays/h5_rw_0.cpp
Normal file
18
doc/reference/c++/arrays/h5_rw_0.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::matrix;
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
array<double, 2> 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<double,2> B; // read the file into B
|
||||||
|
matrix<double> B; // read the file into B
|
||||||
|
h5_read(file, "A", B);
|
||||||
|
std::cout << "B = " << B << std::endl;
|
||||||
|
h5_write(file, "B", B);
|
||||||
|
}
|
||||||
|
|
@ -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<triqs::arrays::array_stack>` 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,21 +18,7 @@ Interaction with CLEF expressions
|
|||||||
|
|
||||||
* **Example** :
|
* **Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./lazy_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::clef::placeholder;
|
|
||||||
int main(){
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
array<double,2> A(2,2), B(2,2);
|
|
||||||
|
|
||||||
A(i_,j_) << i_ + 2*j_ ;
|
|
||||||
B(i_,j_) << A(j_,i_)/2;
|
|
||||||
|
|
||||||
std::cout << "A = "<<A << std::endl;
|
|
||||||
std::cout << "B = "<<B << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
The syntax uses a <<, not = since the array is not assigned to an expression
|
The syntax uses a <<, not = since the array is not assigned to an expression
|
||||||
but filled by the evaluation thereof.
|
but filled by the evaluation thereof.
|
||||||
|
15
doc/reference/c++/arrays/lazy_0.cpp
Normal file
15
doc/reference/c++/arrays/lazy_0.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
array<double, 2> A(2, 2), B(2, 2);
|
||||||
|
|
||||||
|
A(i_, j_) << i_ + 2 * j_;
|
||||||
|
B(i_, j_) << A(j_, i_) / 2;
|
||||||
|
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
std::cout << "B = " << B << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -41,25 +41,7 @@ map
|
|||||||
|
|
||||||
* **Example** :
|
* **Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./map_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
using namespace triqs;
|
|
||||||
int main() {
|
|
||||||
// declare and init a matrix
|
|
||||||
clef::placeholder<0> i_; clef::placeholder<1> j_;
|
|
||||||
arrays::matrix<int> A (2,2); A(i_,j_) << i_ + j_ ;
|
|
||||||
|
|
||||||
// the mapped function
|
|
||||||
auto F = arrays::map([](int i) { return i*2.5;});
|
|
||||||
|
|
||||||
std::cout<< "A = " << A << std::endl;
|
|
||||||
std::cout<< "F(A) = " << F(A) << std::endl; // oops no computation done
|
|
||||||
std::cout<< "F(A) = " << make_matrix(F(A)) << std::endl;
|
|
||||||
std::cout<< "3*F(2*A) = " << make_matrix(3*F(2*A)) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fold
|
fold
|
||||||
========================================================
|
========================================================
|
||||||
|
|
||||||
@ -113,30 +95,7 @@ fold
|
|||||||
|
|
||||||
reads :
|
reads :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./map_1.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <triqs/arrays/functional/fold.hpp>
|
|
||||||
using namespace triqs;
|
|
||||||
|
|
||||||
double frobenius_norm (arrays::matrix<double> const& a) {
|
|
||||||
auto l= [](double r, double x) {
|
|
||||||
auto ab = std::abs(x);
|
|
||||||
return r + ab * ab;
|
|
||||||
};
|
|
||||||
return std::sqrt(arrays::fold(l)(a,0));
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// declare and init a matrix
|
|
||||||
clef::placeholder<0> i_; clef::placeholder<1> j_;
|
|
||||||
arrays::matrix<double> A (2,2); A(i_,j_) << i_ + j_/2.0;
|
|
||||||
|
|
||||||
std::cout<< "A = " << A << std::endl;
|
|
||||||
std::cout<< "||A|| = " << frobenius_norm(A) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Note in this example :
|
Note in this example :
|
||||||
|
|
||||||
* the simplicity of the code
|
* the simplicity of the code
|
||||||
|
18
doc/reference/c++/arrays/map_0.cpp
Normal file
18
doc/reference/c++/arrays/map_0.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
using namespace triqs;
|
||||||
|
int main() {
|
||||||
|
// declare and init a matrix
|
||||||
|
clef::placeholder<0> i_;
|
||||||
|
clef::placeholder<1> j_;
|
||||||
|
arrays::matrix<int> A(2, 2);
|
||||||
|
A(i_, j_) << i_ + j_;
|
||||||
|
|
||||||
|
// the mapped function
|
||||||
|
auto F = arrays::map([](int i) { return i * 2.5; });
|
||||||
|
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
std::cout << "F(A) = " << F(A) << std::endl; // oops no computation done
|
||||||
|
std::cout << "F(A) = " << make_matrix(F(A)) << std::endl;
|
||||||
|
std::cout << "3*F(2*A) = " << make_matrix(3 * F(2 * A)) << std::endl;
|
||||||
|
}
|
||||||
|
|
23
doc/reference/c++/arrays/map_1.cpp
Normal file
23
doc/reference/c++/arrays/map_1.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <triqs/arrays/functional/fold.hpp>
|
||||||
|
using namespace triqs;
|
||||||
|
|
||||||
|
double frobenius_norm(arrays::matrix<double> const& a) {
|
||||||
|
auto l = [](double r, double x) {
|
||||||
|
auto ab = std::abs(x);
|
||||||
|
return r + ab * ab;
|
||||||
|
};
|
||||||
|
return std::sqrt(arrays::fold(l)(a, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// declare and init a matrix
|
||||||
|
clef::placeholder<0> i_;
|
||||||
|
clef::placeholder<1> j_;
|
||||||
|
arrays::matrix<double> A(2, 2);
|
||||||
|
A(i_, j_) << i_ + j_ / 2.0;
|
||||||
|
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
std::cout << "||A|| = " << frobenius_norm(A) << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -34,26 +34,4 @@ make_immutable_array
|
|||||||
|
|
||||||
**Example** :
|
**Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./play_with_concept_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <triqs/arrays/make_immutable_array.hpp>
|
|
||||||
using triqs::arrays::array; using triqs::arrays::range; using triqs::clef::placeholder;
|
|
||||||
int main() {
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
|
|
||||||
auto a = make_immutable_array( 1.0/(2 + i_ + j_), i_= range(0,2), j_=range(0,2));
|
|
||||||
|
|
||||||
std::cout << "a = " << a << std::endl;
|
|
||||||
std::cout << "a = " << array<double,2>(a) << std::endl;
|
|
||||||
|
|
||||||
// or if you prefer using a lambda...
|
|
||||||
auto b = make_immutable_array ( [](int i, int j) { return i-j;}, range (0,2), range(0,2));
|
|
||||||
|
|
||||||
std::cout << "b = " << b << std::endl;
|
|
||||||
std::cout << "b = " << array<double,2>(b) << std::endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
21
doc/reference/c++/arrays/play_with_concept_0.cpp
Normal file
21
doc/reference/c++/arrays/play_with_concept_0.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <triqs/arrays/make_immutable_array.hpp>
|
||||||
|
using triqs::arrays::array;
|
||||||
|
using triqs::arrays::range;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
|
||||||
|
auto a = make_immutable_array(1.0 / (2 + i_ + j_), i_ = range(0, 2), j_ = range(0, 2));
|
||||||
|
|
||||||
|
std::cout << "a = " << a << std::endl;
|
||||||
|
std::cout << "a = " << array<double, 2>(a) << std::endl;
|
||||||
|
|
||||||
|
// or if you prefer using a lambda...
|
||||||
|
auto b = make_immutable_array([](int i, int j) { return i - j; }, range(0, 2), range(0, 2));
|
||||||
|
|
||||||
|
std::cout << "b = " << b << std::endl;
|
||||||
|
std::cout << "b = " << array<double, 2>(b) << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -20,17 +20,4 @@ Shape & dimensions
|
|||||||
|
|
||||||
The shape and dimensions of any object modeling :ref:`ImmutableCuboidArray` is obtained using get_shape and xxx_dim functions :
|
The shape and dimensions of any object modeling :ref:`ImmutableCuboidArray` is obtained using get_shape and xxx_dim functions :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./shape_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
using namespace triqs::arrays;
|
|
||||||
int main () {
|
|
||||||
auto a = array<double,2> (2,3);
|
|
||||||
std::cout << get_shape(a)<< std::endl;
|
|
||||||
std::cout << first_dim(a)<< std::endl;
|
|
||||||
std::cout << second_dim(a)<< std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
10
doc/reference/c++/arrays/shape_0.cpp
Normal file
10
doc/reference/c++/arrays/shape_0.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace triqs::arrays;
|
||||||
|
int main() {
|
||||||
|
auto a = array<double, 2>(2, 3);
|
||||||
|
std::cout << get_shape(a) << std::endl;
|
||||||
|
std::cout << first_dim(a) << std::endl;
|
||||||
|
std::cout << second_dim(a) << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -51,20 +51,4 @@ Returns the maximum/minimum element of the array (provided that value_type is an
|
|||||||
Examples
|
Examples
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./simple_fnt_0.cpp
|
||||||
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <triqs/arrays/algorithms.hpp>
|
|
||||||
using triqs::arrays::matrix; using triqs::clef::placeholder;
|
|
||||||
int main() {
|
|
||||||
// declare and init a matrix
|
|
||||||
placeholder<0> i_; placeholder<1> j_;
|
|
||||||
matrix<int> A (2,2); A(i_,j_) << i_ - j_ ;
|
|
||||||
|
|
||||||
std::cout << "A = " << A << std::endl;
|
|
||||||
std::cout << "abs(A)= " << matrix<double>(abs(A)) << std::endl;
|
|
||||||
std::cout << "sum(A) = " << sum(A) << std::endl;
|
|
||||||
std::cout << "max_element(A) = " << max_element(A) << std::endl;
|
|
||||||
std::cout << "min_element(A) = " << min_element(A) << std::endl;
|
|
||||||
std::cout << "min_element(abs(A)) = " << min_element(abs(A)) << std::endl;
|
|
||||||
}
|
|
||||||
|
18
doc/reference/c++/arrays/simple_fnt_0.cpp
Normal file
18
doc/reference/c++/arrays/simple_fnt_0.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <triqs/arrays/algorithms.hpp>
|
||||||
|
using triqs::arrays::matrix;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
// declare and init a matrix
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> j_;
|
||||||
|
matrix<int> A(2, 2);
|
||||||
|
A(i_, j_) << i_ - j_;
|
||||||
|
|
||||||
|
std::cout << "A = " << A << std::endl;
|
||||||
|
std::cout << "abs(A)= " << matrix<double>(abs(A)) << std::endl;
|
||||||
|
std::cout << "sum(A) = " << sum(A) << std::endl;
|
||||||
|
std::cout << "max_element(A) = " << max_element(A) << std::endl;
|
||||||
|
std::cout << "min_element(A) = " << min_element(A) << std::endl;
|
||||||
|
std::cout << "min_element(abs(A)) = " << min_element(abs(A)) << std::endl;
|
||||||
|
}
|
2
doc/reference/c++/clef/CMakeLists.txt
Normal file
2
doc/reference/c++/clef/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
all_tests()
|
||||||
|
|
@ -33,33 +33,7 @@ and also for some STL container like std::vector.
|
|||||||
|
|
||||||
Example :
|
Example :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./assign_0.cpp
|
||||||
|
|
||||||
#include "triqs/clef.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
using namespace triqs::clef;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int N = 5;
|
|
||||||
double pi = std::acos(-1);
|
|
||||||
|
|
||||||
// automatic assignment of vector
|
|
||||||
placeholder <0> k_;
|
|
||||||
std::vector<double> V(N);
|
|
||||||
make_expr(V) [k_] << cos( (2* pi* k_)/ N );
|
|
||||||
|
|
||||||
// chaining them ...
|
|
||||||
placeholder <1> i_;
|
|
||||||
std::vector<std::vector<double>> W(3, std::vector<double>(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!";
|
|
||||||
}
|
|
||||||
|
|
||||||
**Details**
|
**Details**
|
||||||
|
|
||||||
The synopsis of the `triqs_clef_auto_assign` functions is ::
|
The synopsis of the `triqs_clef_auto_assign` functions is ::
|
||||||
@ -92,26 +66,4 @@ into ::
|
|||||||
|
|
||||||
A complete example :
|
A complete example :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./assign_1.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
using namespace triqs::clef;
|
|
||||||
|
|
||||||
struct Obj{
|
|
||||||
double v;
|
|
||||||
TRIQS_CLEF_IMPLEMENT_LAZY_CALL();
|
|
||||||
//
|
|
||||||
template<typename Fnt> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
26
doc/reference/c++/clef/assign_0.cpp
Normal file
26
doc/reference/c++/clef/assign_0.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "triqs/clef.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
using namespace triqs::clef;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N = 5;
|
||||||
|
double pi = std::acos(-1);
|
||||||
|
|
||||||
|
// automatic assignment of vector
|
||||||
|
placeholder<0> k_;
|
||||||
|
std::vector<double> V(N);
|
||||||
|
make_expr(V)[k_] << cos((2 * pi * k_) / N);
|
||||||
|
|
||||||
|
// chaining them ...
|
||||||
|
placeholder<1> i_;
|
||||||
|
std::vector<std::vector<double>> W(3, std::vector<double>(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!";
|
||||||
|
}
|
||||||
|
|
21
doc/reference/c++/clef/assign_1.cpp
Normal file
21
doc/reference/c++/clef/assign_1.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace triqs::clef;
|
||||||
|
|
||||||
|
struct Obj {
|
||||||
|
double v;
|
||||||
|
TRIQS_CLEF_IMPLEMENT_LAZY_CALL();
|
||||||
|
//
|
||||||
|
template <typename Fnt> 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;
|
||||||
|
}
|
||||||
|
|
@ -22,16 +22,7 @@ The evaluation can be :
|
|||||||
Complete evaluation
|
Complete evaluation
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./expressions_eval_0.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Note that :
|
Note that :
|
||||||
|
|
||||||
* The order of placeholder does not matter in calling eval.
|
* The order of placeholder does not matter in calling eval.
|
||||||
|
9
doc/reference/c++/clef/expressions_eval_0.cpp
Normal file
9
doc/reference/c++/clef/expressions_eval_0.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -44,26 +44,7 @@ CLEF expressions are made of :
|
|||||||
|
|
||||||
Examples :
|
Examples :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./expressions_form_0.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <vector>
|
|
||||||
using namespace triqs::clef;
|
|
||||||
int main () {
|
|
||||||
placeholder<0> i_; placeholder<1> x_; placeholder<2> y_;
|
|
||||||
std::vector<int> 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_];
|
|
||||||
}
|
|
||||||
|
|
||||||
Note that :
|
Note that :
|
||||||
|
|
||||||
* Expressions do not compute anything, they just store the expression tree.
|
* Expressions do not compute anything, they just store the expression tree.
|
||||||
|
20
doc/reference/c++/clef/expressions_form_0.cpp
Normal file
20
doc/reference/c++/clef/expressions_form_0.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <vector>
|
||||||
|
using namespace triqs::clef;
|
||||||
|
int main() {
|
||||||
|
placeholder<0> i_;
|
||||||
|
placeholder<1> x_;
|
||||||
|
placeholder<2> y_;
|
||||||
|
std::vector<int> 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_];
|
||||||
|
}
|
||||||
|
|
@ -74,50 +74,4 @@ clef::function can be assigned with the = operator, Cf example below.
|
|||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./function_0.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
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<double(double)> F(f);
|
|
||||||
}
|
|
||||||
{ //with two variables
|
|
||||||
auto f = make_function(2*x_ + y_ + 1, x_, y_);
|
|
||||||
std::cout << f(3,4) << std::endl;
|
|
||||||
std::function<double(double,double)> 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<double(double,double)> f2,g2;
|
|
||||||
f2(x_,y_) = x_ + y_;
|
|
||||||
std::cout << f2(2,3) << std::endl;
|
|
||||||
|
|
||||||
std::function<double(double,double)> sf2 = f2;
|
|
||||||
std::cout << sf2(2,3) << std::endl;
|
|
||||||
|
|
||||||
g2(x_,y_) = x_ - y_ + f2(x_,2*y_);
|
|
||||||
|
|
||||||
std::function<double(double)> sf = x_>> 2*x_ + 1;
|
|
||||||
std::cout << sf(3) << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
46
doc/reference/c++/clef/function_0.cpp
Normal file
46
doc/reference/c++/clef/function_0.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
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<double(double)> F(f);
|
||||||
|
}
|
||||||
|
{ // with two variables
|
||||||
|
auto f = make_function(2 * x_ + y_ + 1, x_, y_);
|
||||||
|
std::cout << f(3, 4) << std::endl;
|
||||||
|
std::function<double(double, double)> 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<double(double, double)> f2, g2;
|
||||||
|
f2(x_, y_) = x_ + y_;
|
||||||
|
std::cout << f2(2, 3) << std::endl;
|
||||||
|
|
||||||
|
std::function<double(double, double)> sf2 = f2;
|
||||||
|
std::cout << sf2(2, 3) << std::endl;
|
||||||
|
|
||||||
|
g2(x_, y_) = x_ - y_ + f2(x_, 2 * y_);
|
||||||
|
|
||||||
|
std::function<double(double)> sf = x_ >> 2 * x_ + 1;
|
||||||
|
std::cout << sf(3) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.
|
As usual, the best is to start with a few examples, to show the library in action.
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./introduction_0.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <triqs/arrays.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
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<double> 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<double> 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<std::vector<double>> W(3, std::vector<double>(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<int(int)> f = i_ >> 2*i_ +1;
|
|
||||||
// a function (i,j) -> 2*i +j
|
|
||||||
std::function<double(int,int)> 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<int> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
63
doc/reference/c++/clef/introduction_0.cpp
Normal file
63
doc/reference/c++/clef/introduction_0.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <triqs/arrays.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
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<double> 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<double> 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<std::vector<double>> W(3, std::vector<double>(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<int(int)> f = i_ >> 2 * i_ + 1;
|
||||||
|
// a function (i,j) -> 2*i +j
|
||||||
|
std::function<double(int, int)> 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<int> 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;
|
||||||
|
}
|
||||||
|
|
@ -19,35 +19,7 @@ using the `TRIQS_CLEF_MAKE_FNT_LAZY` macro.
|
|||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./overload_0.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// 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<NotClefExpression T>
|
|
||||||
// T bar (T const & x) { return x+1;}
|
|
||||||
|
|
||||||
// C++11 workaround
|
|
||||||
template<typename T>
|
|
||||||
typename std::enable_if<!triqs::clef::is_clef_expression<T>::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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Note that :
|
Note that :
|
||||||
|
|
||||||
* This overload **must** be defined in the triqs::clef namespace, since it is found by ADL.
|
* This overload **must** be defined in the triqs::clef namespace, since it is found by ADL.
|
||||||
@ -55,16 +27,7 @@ Note that :
|
|||||||
* The function `bar` can be a template, BUT then the template must be disabled for lazy expressions.
|
* The function `bar` can be a template, BUT then the template must be disabled for lazy expressions.
|
||||||
* The overload is already defined by clef for usual functions :
|
* The overload is already defined by clef for usual functions :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./overload_1.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
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::
|
|
||||||
}
|
|
||||||
|
|
||||||
.. _callable_object:
|
.. _callable_object:
|
||||||
|
|
||||||
Overloading operator() and other methods
|
Overloading operator() and other methods
|
||||||
@ -79,47 +42,7 @@ It is an ordinary operator() that must :
|
|||||||
|
|
||||||
Example :
|
Example :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./overload_2.cpp
|
||||||
|
|
||||||
#include <triqs/clef.hpp>
|
|
||||||
|
|
||||||
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 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
**NB** When the method or the non CLEF operator() is already a template,
|
**NB** When the method or the non CLEF operator() is already a template,
|
||||||
it must be disabled for clef expression argument, using the trait ::
|
it must be disabled for clef expression argument, using the trait ::
|
||||||
|
|
||||||
|
32
doc/reference/c++/clef/overload_0.cpp
Normal file
32
doc/reference/c++/clef/overload_0.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// 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<NotClefExpression T>
|
||||||
|
// T bar (T const & x) { return x+1;}
|
||||||
|
|
||||||
|
// C++11 workaround
|
||||||
|
template <typename T> typename std::enable_if<!triqs::clef::is_clef_expression<T>::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;
|
||||||
|
}
|
||||||
|
|
8
doc/reference/c++/clef/overload_1.cpp
Normal file
8
doc/reference/c++/clef/overload_1.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
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::
|
||||||
|
}
|
||||||
|
|
40
doc/reference/c++/clef/overload_2.cpp
Normal file
40
doc/reference/c++/clef/overload_2.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <triqs/clef.hpp>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,5 @@
|
|||||||
# Doxygen sources
|
# Doxygen sources
|
||||||
set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_SOURCE_DIR}/triqs/det_manip/det_manip.hpp)
|
set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_SOURCE_DIR}/triqs/det_manip/det_manip.hpp)
|
||||||
|
|
||||||
|
all_tests()
|
||||||
|
|
||||||
|
@ -153,51 +153,4 @@ The :doxy:`full C++ documentation<triqs::det_manip::det_manip>` is available her
|
|||||||
Example
|
Example
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./det_manip_0.cpp
|
||||||
|
|
||||||
#include <triqs/det_manip/det_manip.hpp>
|
|
||||||
|
|
||||||
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<fun> 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
41
doc/reference/c++/det_manip/det_manip_0.cpp
Normal file
41
doc/reference/c++/det_manip/det_manip_0.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <triqs/det_manip/det_manip.hpp>
|
||||||
|
|
||||||
|
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<fun> 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();
|
||||||
|
}
|
||||||
|
|
@ -8,3 +8,6 @@ set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES
|
|||||||
${TRIQS_GFS_SRC_DIR}/refreq.hpp
|
${TRIQS_GFS_SRC_DIR}/refreq.hpp
|
||||||
${TRIQS_GFS_SRC_DIR}/domains/matsubara.hpp
|
${TRIQS_GFS_SRC_DIR}/domains/matsubara.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
all_tests()
|
||||||
|
|
||||||
|
@ -17,22 +17,7 @@ Using the CLEF library offers a quick and efficient way to fill an array with mu
|
|||||||
|
|
||||||
**Example** :
|
**Example** :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./clef_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
using namespace triqs::gfs; using triqs::clef::placeholder;
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
// Cf gf<imfreq> specialisation page for the constructor
|
|
||||||
double beta=10; int Nfreq =100;
|
|
||||||
auto g = gf<imfreq> { {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_) );
|
|
||||||
}
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
The LHS uses () and not brackets, even though it is on the mesh, because of the strange C++ limitation
|
The LHS uses () and not brackets, even though it is on the mesh, because of the strange C++ limitation
|
||||||
|
16
doc/reference/c++/gf/clef_0.cpp
Normal file
16
doc/reference/c++/gf/clef_0.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
using namespace triqs::gfs;
|
||||||
|
using triqs::clef::placeholder;
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
// Cf gf<imfreq> specialisation page for the constructor
|
||||||
|
double beta = 10;
|
||||||
|
int Nfreq = 100;
|
||||||
|
auto g = gf<imfreq>{{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_));
|
||||||
|
}
|
||||||
|
|
@ -65,27 +65,7 @@ DOC TO BE FINISHED.
|
|||||||
Example
|
Example
|
||||||
=========
|
=========
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./fourier_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
using namespace triqs::gfs;
|
|
||||||
int main() {
|
|
||||||
double beta =1, a=1;
|
|
||||||
int N=10000;
|
|
||||||
auto gw = gf<imfreq> {{beta, Fermion, N}, {1,1}};
|
|
||||||
auto gt = gf<imtime> {{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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Convention
|
Convention
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
19
doc/reference/c++/gf/fourier_0.cpp
Normal file
19
doc/reference/c++/gf/fourier_0.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
using namespace triqs::gfs;
|
||||||
|
int main() {
|
||||||
|
double beta = 1, a = 1;
|
||||||
|
int N = 10000;
|
||||||
|
auto gw = gf<imfreq>{{beta, Fermion, N}, {1, 1}};
|
||||||
|
auto gt = gf<imtime>{{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);
|
||||||
|
}
|
||||||
|
|
@ -129,36 +129,4 @@ Block gf have a natural iterator, e.g. ::
|
|||||||
|
|
||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_block_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<imfreq> (3);
|
|
||||||
|
|
||||||
// make a few gf<imfreq> ...
|
|
||||||
auto g1 = gf<imfreq> ({beta, Fermion}, {2,2});
|
|
||||||
|
|
||||||
// ... and construct some block function out of them.
|
|
||||||
auto Bg1 = make_block_gf<imfreq> (3, g1);
|
|
||||||
auto Bg2 = make_block_gf<imfreq> ({g1,g1,g1});
|
|
||||||
auto Bg3 = make_block_gf<imfreq> ({"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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
31
doc/reference/c++/gf/gf_block_0.cpp
Normal file
31
doc/reference/c++/gf/gf_block_0.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<imfreq>(3);
|
||||||
|
|
||||||
|
// make a few gf<imfreq> ...
|
||||||
|
auto g1 = gf<imfreq>({beta, Fermion}, {2, 2});
|
||||||
|
|
||||||
|
// ... and construct some block function out of them.
|
||||||
|
auto Bg1 = make_block_gf<imfreq>(3, g1);
|
||||||
|
auto Bg2 = make_block_gf<imfreq>({g1, g1, g1});
|
||||||
|
auto Bg3 = make_block_gf<imfreq>({"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);
|
||||||
|
}
|
||||||
|
|
@ -40,15 +40,4 @@ Examples
|
|||||||
There are more examples for each specializations in the corresponding pages.
|
There are more examples for each specializations in the corresponding pages.
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_constructors_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
using namespace triqs::gfs;
|
|
||||||
int main(){
|
|
||||||
auto beta = 10.0;
|
|
||||||
gf<imfreq> gf { {beta, Fermion}, {1,1}};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
7
doc/reference/c++/gf/gf_constructors_0.cpp
Normal file
7
doc/reference/c++/gf/gf_constructors_0.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
using namespace triqs::gfs;
|
||||||
|
int main() {
|
||||||
|
auto beta = 10.0;
|
||||||
|
gf<imfreq> gf{{beta, Fermion}, {1, 1}};
|
||||||
|
}
|
||||||
|
|
@ -82,40 +82,4 @@ Examples
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_imfreq_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<imfreq> { {beta,Fermion,Nfreq}, {1,1} };
|
|
||||||
// or a more verbose/explicit form ...
|
|
||||||
auto g2 = gf<imfreq> { gf_mesh<imfreq>{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<imfreq,scalar_valued> { {beta,Fermion,Nfreq} };
|
|
||||||
auto g4 = gf<imfreq,scalar_valued> { gf_mesh<imfreq>{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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
34
doc/reference/c++/gf/gf_imfreq_0.cpp
Normal file
34
doc/reference/c++/gf/gf_imfreq_0.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<imfreq>{{beta, Fermion, Nfreq}, {1, 1}};
|
||||||
|
// or a more verbose/explicit form ...
|
||||||
|
auto g2 = gf<imfreq>{gf_mesh<imfreq>{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<imfreq, scalar_valued>{{beta, Fermion, Nfreq}};
|
||||||
|
auto g4 = gf<imfreq, scalar_valued>{gf_mesh<imfreq>{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;
|
||||||
|
}
|
||||||
|
|
@ -87,41 +87,5 @@ h5 tag : `ImTime`
|
|||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_imtime_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<imtime, matrix_valued, no_tail> { {beta,Fermion,n_times}, {1,1} };
|
|
||||||
|
|
||||||
// or a more verbose/explicit form ...
|
|
||||||
auto g2 = gf<imtime> { gf_mesh<imtime>{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<imtime, scalar_valued, no_tail> { {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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
32
doc/reference/c++/gf/gf_imtime_0.cpp
Normal file
32
doc/reference/c++/gf/gf_imtime_0.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<imtime, matrix_valued, no_tail>{{beta, Fermion, n_times}, {1, 1}};
|
||||||
|
|
||||||
|
// or a more verbose/explicit form ...
|
||||||
|
auto g2 = gf<imtime>{gf_mesh<imtime>{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<imtime, scalar_valued, no_tail>{{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;
|
||||||
|
}
|
||||||
|
|
@ -53,14 +53,4 @@ h5 tag : `Legendre`
|
|||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_legendre_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
using namespace triqs::gfs;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// We want a 2x2 matrix valued function on this mesh...
|
|
||||||
//auto g = gf<legendre> { {wmin, wmax, n_freq}, {2,2} };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
8
doc/reference/c++/gf/gf_legendre_0.cpp
Normal file
8
doc/reference/c++/gf/gf_legendre_0.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
using namespace triqs::gfs;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// We want a 2x2 matrix valued function on this mesh...
|
||||||
|
// auto g = gf<legendre> { {wmin, wmax, n_freq}, {2,2} };
|
||||||
|
};
|
||||||
|
|
@ -26,27 +26,7 @@ Partial evaluation
|
|||||||
|
|
||||||
Probably an example would help here ... :
|
Probably an example would help here ... :
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_part_eval_curry_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<cartesian_product<retime,imtime>, 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<retime> seeing the value at the index 3
|
|
||||||
|
|
||||||
std::cout<< g_sliced<< std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Currying
|
Currying
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@ -62,36 +42,4 @@ Currying
|
|||||||
curry(gf_view<cartesian_product<Ms...>, Target, Opt, IsConst> g);
|
curry(gf_view<cartesian_product<Ms...>, Target, Opt, IsConst> g);
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_part_eval_curry_1.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<cartesian_product<refreq,imfreq>, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
19
doc/reference/c++/gf/gf_part_eval_curry_0.cpp
Normal file
19
doc/reference/c++/gf/gf_part_eval_curry_0.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<cartesian_product<retime, imtime>, 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<retime> seeing the value at the index 3
|
||||||
|
|
||||||
|
std::cout << g_sliced << std::endl;
|
||||||
|
}
|
||||||
|
|
27
doc/reference/c++/gf/gf_part_eval_curry_1.cpp
Normal file
27
doc/reference/c++/gf/gf_part_eval_curry_1.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<cartesian_product<refreq, imfreq>, 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;
|
||||||
|
}
|
||||||
|
|
@ -55,37 +55,4 @@ See :
|
|||||||
|
|
||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_product_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<cartesian_product<retime,imtime>, scalar_valued>;
|
|
||||||
using g_t_tau_m = gf<cartesian_product<retime,imtime>, matrix_valued>;
|
|
||||||
using g_t_tau_t = gf<cartesian_product<retime,imtime>, tensor_valued<3>>;
|
|
||||||
|
|
||||||
// a scalar valued function
|
|
||||||
auto m1 = gf_mesh<retime>{tmin, tmax, n_re_time};
|
|
||||||
auto m2 = gf_mesh<imtime>{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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
30
doc/reference/c++/gf/gf_product_0.cpp
Normal file
30
doc/reference/c++/gf/gf_product_0.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<cartesian_product<retime, imtime>, scalar_valued>;
|
||||||
|
using g_t_tau_m = gf<cartesian_product<retime, imtime>, matrix_valued>;
|
||||||
|
using g_t_tau_t = gf<cartesian_product<retime, imtime>, tensor_valued<3>>;
|
||||||
|
|
||||||
|
// a scalar valued function
|
||||||
|
auto m1 = gf_mesh<retime>{tmin, tmax, n_re_time};
|
||||||
|
auto m2 = gf_mesh<imtime>{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);
|
||||||
|
}
|
||||||
|
|
@ -80,17 +80,4 @@ h5 tag : `ReFreq`
|
|||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_refreq_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<refreq> { {wmin, wmax, n_freq}, {2,2} };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
11
doc/reference/c++/gf/gf_refreq_0.cpp
Normal file
11
doc/reference/c++/gf/gf_refreq_0.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<refreq>{{wmin, wmax, n_freq}, {2, 2}};
|
||||||
|
};
|
||||||
|
|
@ -81,16 +81,4 @@ h5 tag : `ReTime`
|
|||||||
Examples
|
Examples
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./gf_retime_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
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<retime>{ {tmin, tmax, n_times} , {2,2} };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
11
doc/reference/c++/gf/gf_retime_0.cpp
Normal file
11
doc/reference/c++/gf/gf_retime_0.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
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<retime>{{tmin, tmax, n_times}, {2, 2}};
|
||||||
|
};
|
||||||
|
|
@ -62,28 +62,4 @@ Public member types
|
|||||||
Example
|
Example
|
||||||
----------
|
----------
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./matsubara_freq_mesh_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs/meshes/matsubara_freq.hpp>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
20
doc/reference/c++/gf/matsubara_freq_mesh_0.cpp
Normal file
20
doc/reference/c++/gf/matsubara_freq_mesh_0.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <triqs/gfs/meshes/matsubara_freq.hpp>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -33,33 +33,7 @@ where
|
|||||||
Example
|
Example
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./set_tail_from_fit_0.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
#include <triqs/gfs/local/fit_tail.hpp>
|
|
||||||
using namespace triqs::gfs;
|
|
||||||
int main(){
|
|
||||||
triqs::clef::placeholder<0> iom_;
|
|
||||||
double beta =10;
|
|
||||||
int N=100;
|
|
||||||
|
|
||||||
auto gw = gf<imfreq>{{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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
23
doc/reference/c++/gf/set_tail_from_fit_0.cpp
Normal file
23
doc/reference/c++/gf/set_tail_from_fit_0.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <triqs/gfs.hpp>
|
||||||
|
#include <triqs/gfs/local/fit_tail.hpp>
|
||||||
|
using namespace triqs::gfs;
|
||||||
|
int main() {
|
||||||
|
triqs::clef::placeholder<0> iom_;
|
||||||
|
double beta = 10;
|
||||||
|
int N = 100;
|
||||||
|
|
||||||
|
auto gw = gf<imfreq>{{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;
|
||||||
|
}
|
||||||
|
|
@ -24,53 +24,14 @@ Implementation
|
|||||||
In TRIQS, the tail is implemented as an object ``tail``. Here is a simple example of use:
|
In TRIQS, the tail is implemented as an object ``tail``. Here is a simple example of use:
|
||||||
|
|
||||||
|
|
||||||
.. compileblock::
|
.. triqs_example:: ./tail_0.cpp
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <triqs/gfs/local/tail.hpp>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Fitting the tail of a Green's function
|
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``:
|
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::
|
.. triqs_example:: ./tail_1.cpp
|
||||||
|
|
||||||
#include <triqs/gfs.hpp>
|
|
||||||
#include <triqs/gfs/local/fit_tail.hpp>
|
|
||||||
using namespace triqs::gfs;
|
|
||||||
int main(){
|
|
||||||
triqs::clef::placeholder<0> iom_;
|
|
||||||
double beta =10;
|
|
||||||
int N=100;
|
|
||||||
|
|
||||||
auto gw = gf<imfreq>{{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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
The full documentation of ``set_tail_from_fit`` is :doc:`here<set_tail_from_fit>`.
|
The full documentation of ``set_tail_from_fit`` is :doc:`here<set_tail_from_fit>`.
|
||||||
|
|
||||||
API
|
API
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user