Basic ============ .. highlight:: c Declaring and printing an array ------------------------------- .. compileblock:: #include using triqs::arrays::array; int main(){ array A(20); std::cout << "A = "< B; // read the file into B h5_read (file, "A",B); std::cout << "B = "< using triqs::arrays::array; using triqs::arrays::array_view; using triqs::arrays::range; int main(){ array A(3,3); A() = 2.5; std::cout << A < B = A(1,range()); //select the first line of the matrix std::cout <<"B = "<< B << std::endl; B(0) = 1; std::cout <<"A = "<< A << std::endl; } Matrices and vectors ------------------------- Arrays must be distinguished from vectors and matrices, which have an algebra of their own. .. compileblock:: #include using triqs::arrays::array; using triqs::arrays::matrix; using triqs::arrays::vector; int main(){ array A(2,2), B(2,2),C; A() = 3; B() = 1; C = A*B; std::cout << "A*B = "<< C << std::endl; matrix D(2,2),E(2,2),F; E() = 3; E() = 1; F = D*E; std::cout << "C*D = "<< F << std::endl; vector u(2),v(2),w; u()=1;v()=2; w = u+v; std::cout <<"u+v = "<< w << std::endl; } Defining through a lazy expression ----------------------------------- .. compileblock:: #include using triqs::arrays::array; namespace tql=triqs::clef; int main(){ tql::placeholder<0> i_; tql::placeholder<1> j_; array A(2,2); A(i_,j_) << i_ + j_ ; std::cout << "A = "< #include using triqs::arrays::array; using triqs::arrays::matrix; using triqs::clef::placeholder; int main(){ placeholder<0> i_; placeholder<1> j_; matrix A(2,2); A(i_,j_) << i_+j_; matrix B = inverse(A); double C = determinant(A); std::cout << "A^(-1) = "<< B << std::endl; std::cout << "det(A) = " < #include using triqs::arrays::array; double f(int i) { return i*10;} int main() { auto F = triqs::arrays::map(std::function(f)); array A(2,2); A() =2; array B,C; A() =2; B = F(A); C = F(2*A); // works also with expressions of course std::cout << "A = "<