.. highlight:: c .. _arith_expression: Arithmetic Expressions ------------------------------------------------- * **Definition** : By `expression`, we mean here an object, typically representing a mathematical expression, which models the :ref:`HasImmutableArrayInterface` concept. * **Use** : Expression can be used : - as RHS (Right Hand Side) of various operators (=, +=, -=, ...) - at any place where an `expression` is expected. * **How to make expression ?** Expressions can be build easily in various ways : - Using arithmetic operators, e.g. A + 2*B Examples :: array A (2,2), B(2,2),C; C= A + 2*B; array D( A+ 2*B); array F( 0.5 * A); // Type promotion is automatic // or even in C++0x : auto e = A + 2*B; // expression, purely formal array D(e); // really makes the computation cout<< e < M1(2,2), M2(2,2), M3; M3 = matmul(M1,M2); will do the following : - matmul returns a lazy object modelling the :ref:`Expression` concept. - a result this is compiled as some `matmul_with_lapack(M1,M2,M3)` : **there is NO intermediate copy**. - mat_vec_mul - Building custom expressions. The transpose example... Describe the concept, what to implement, etc.... - Transpose:: array A (2,2), B(2,2),C(2,2); C= A + 2*B; C = A + Transpose(B); // Transpose(X) returns a lazy object that models HasImmutableArrayInterface. C = A + Transpose(B + B); // X can also be an expression... C = Transpose(B); // // non square array R(2,3),Rt(3,2); cout<<" R = "<< array(Transpose(R)) <