KADATH
index.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "index.hpp"
20 #include "tensor.hpp"
21 
22 namespace Kadath {
23 
24 
25 // Constructor fro a tensor :
26 Index::Index (const Tensor& t) : sizes{t.valence}, coord{sizes.get_ndim()} {
27  for (int i=0 ; i<get_ndim() ; i++) {
28  coord[i] = 0;
29  sizes.set(i) = t.get_ndim();
30  }
31 }
32 
33 // Increment
34 
35 
36 ostream& operator<< (ostream& o, const Index& so) {
37 
38  o << "(" ;
39  for (int i=0 ; i<so.get_ndim()-1 ; i++)
40  o << so.coord[i] << ", " ;
41  o << so.coord[so.get_ndim()-1] << ") in an array of " ;
42  o << so.sizes << " points." ;
43  return o ;
44 }
45 }
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
Dim_array sizes
Sizes of the associated Array.
Definition: index.hpp:48
Data_type coord
Value of each index.
Definition: index.hpp:49
int get_ndim() const
Returns the number of dimensions.
Definition: index.hpp:81
Index(const Dim_array &dim)
Standard constructor.
Definition: index.hpp:57
Tensor handling.
Definition: tensor.hpp:149
int get_ndim() const
Returns the number dimension.
Definition: tensor.hpp:519