.. highlight:: c array and array_view : declaration & construction ==================================================================================================================== array and array_view : * are the standard d-dimensional cuboid array and the corresponding view. * allow **custom memory ordering** at compile time. * model the :ref:`HasImmutableArrayInterface` concept. Template parameters ---------------------------- * The classes have three template parameters. .. code-block:: c template class array_view; template class array; ============================ ================================== ========================== ==================================================================== Template parameter Accepted type Access in the class Meaning ============================ ================================== ========================== ==================================================================== ValueType normally a scalar, but any default value_type The type of the element of the array constructible type (?). Rank int rank The rank of the array Opt Option::options< ...> opt_type Compile time options, see below. ============================ ================================== ========================== ==================================================================== Options template parameters are described :ref:`here `. .. _array_constructors: Constructors of array --------------------------- ========================================== =========================================================================================== Constructors of array Comments ========================================== =========================================================================================== array() - Empty array of size 0 array(const array &) - Copy constructor array(array &&) - Move constructor array(size_t, ...., size_t) - From the dimensions [number of parameters checked at compile time]. Does **NOT** initialize the array elements to 0 ! (see compile time option) Use my_array() =0 to do it explicitely. array(cuboid_domain const &) - New array with the corresponding domain array(PyObject * X) - Construct a new array from the Python object X. NB : X is a borrowed reference, array does affect its counting reference. - it takes a **copy** of the data of X (or of numpy(X)) into C++. - X is first transformed into a numpy by the python numpy lib itself (as if you call numpy.array(X)) if X is not a numpy array or an array of the wrong type (e.g. you construct an array from a numpy of int....), and copied into the array. array(const T & X) - Type T models the :ref:`HasImmutableArrayInterface` concept. - X must have the appropriate domain (checked at compile time). - Constructs a new array of domain X.domain() and fills it with evaluation of X. ========================================== =========================================================================================== .. warning:: The constructor from the dimensions does **NOT** initialize the matrix to 0 (because it may not be optimal). If needed, do it explicitely by (a if the array) `a()=0`; - LAYOUT Examples ------------ .. compileblock:: #include 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 A3(1,2,3); // A 2d array of double, C ordering, with explicit Bound Checking array B(1,2); // a matrix of long matrix M(2,2); // a vector of double vector V(10); // arrays with custom TraversalOrder // C-style array A0(2,3,4); array A0b; // same type but empty // Fortran-style array A4 (2,3,4); array A1b(); //same type but empty // custom : (i,j,k) : index j is fastest, then k, then i array A2(2,3,4); } Constructors of array_views ---------------------------------------------- Automatic construction ^^^^^^^^^^^^^^^^^^^^^^^^^^^ array_view are normally automatically constructed by making (partial) views, ref:`Slicing`, e.g. :: array A(2,2); A(range(),2) ; // --> this makes a view... A() ; // --> this makes a view over the full array Explicit construction ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To explicitly make a view of an array, use make_view or the ():: array A(2,2); make_view(A); //-> a view... make_view(A) = 13 ; // to assign e.g. A() = 13; // same thing... ====================================================================== ===================================================================================================== Constructors of array_view Comments ====================================================================== ===================================================================================================== array_view(const array_view &) - Copy construction (shallow copy) array_view(const T & X) - `[Advanced]` T is any type such that X.indexmap() and X.storage() can be used to construct a view. array_view(indexmap_type const & I, S_type const &) - `[Advanced]` From a couple of indexmap I and storage of type S_type. ====================================================================== =====================================================================================================