3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-01 19:53:45 +01:00
dft_tools/doc/reference/c++/arrays/containers/call.rst
Olivier Parcollet 3fe400d34c 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)
2014-05-31 23:00:16 +02:00

105 lines
2.8 KiB
ReStructuredText

.. highlight:: c
.. _arr_call:
Operator()
==================================
**Synopsis** ::
value_type const & operator()(size_t ...) const (1a)
value_type & operator()(size_t ...) (1b)
view_type operator()() const (2a)
view_type operator()( size_t | range | ellipsis ) const (2b)
`clef expression` operator()( `at least a lazy argument` ) const (3)
This is valid for both the container (e.g. array), and the view (e.g. array_view).
.. _arr_element_access:
(1) Element access
---------------------------------
Following the concept :ref:`ImmutableCuboidArray`, the form (1) is an access to the elements.
It must be called with exactly `rank` size_t (or it is a compile time error).
Example
^^^^^^^^^
.. triqs_example:: ./call_0.cpp
Another ::
A(1, range(0,2) ) // 1d slice
A(1, range()) // 1d slice taking all the second dim
A(range(0,10,2), range(0,10,2)) // a 2d slice viewing every each elements with even coordinates.
array_view<T,1> SL = A(0,range(0,3)); // naming the view. No data copied here !
array_view<T,1> SL ( A(0,range(0,3))); // same thing !
.. _arr_making_view:
(2) Building a view
---------------------------------
When the arguments contains at least one :ref:`range<arr_range>` or one :ref:`ellipsis<arr_ellipsis>`, and no placeholder (see 3)),
the return type is a (partial) view of the container.
The special case (2a) (no argument) returns a complete view of the object
(equivalent to view_type(* this)).
The return type of the () operator is :
* Partial views of array or array_view return a array_view.
* Partial views of vector or vector_view return a vector_view.
* 2d partial views of matrix or matrix_view return a matrix_view.
* BUT : (1d) partial view of matrix or matrix_view return a vector_view.
Example
^^^^^^^^^^^^
.. triqs_example:: ./call_1.cpp
.. toctree::
:hidden:
range_ell
.. highlight:: c
.. _arr_lazy:
(3) Interaction with clef expressions
-------------------------------------------------
* The containers and their views can be used with the triqs::clef library :
* Using the clef library offers a quick and efficient way to fill an array with multiple advantages :
* It is simpler and more readeable than a series of for loops.
* It is usually more optimal since the for loops are automatically written in the TraversalOrder of the
array.
* NB : the expression can be (and are) inlined by the compilers...
* **Example** :
.. triqs_example:: ./call_2.cpp
.. note::
The syntax uses a <<, not = since the array is not assigned to an expression
but filled by the evaluation thereof.