Grid 0.7.0
Coordinate.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/cartesian/Coordinate.h
6
7 Copyright (C) 2018
8
9 Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26*************************************************************************************/
27/* END LEGAL */
28#pragma once
29
31// Provide a stack resident container for coordinates, or extents
34template<class _T,int MaxEntries>
36public:
37
38 typedef _T value;
39 typedef int size_type;
40 typedef value & reference;
41 typedef const value & const_reference;
42 typedef value * pointer;
43 typedef const value * const_pointer;
44
45private:
46 value _data[MaxEntries];
48
49public:
52 accelerator_inline size_type size(void) const { return _size; };
55#ifndef GRID_HIP
56 assert(sz>=0);
57 assert(sz<=MaxEntries);
58#endif
59 _size = sz;
60 }
62 resize(sz);
63 for(int s=0;s<sz;s++) _data[s]=val;
64 }
65 accelerator_inline pointer begin(void) { return &_data[0]; }
66 accelerator_inline const_pointer begin(void) const { return &_data[0]; }
68 accelerator_inline const_pointer end (void) const { return &_data[_size]; }
69 accelerator_inline void push_back(const value &val) { resize(_size+1); _data[_size-1] = val;}
73 AcceleratorVector(const std::vector<value> &copyme) {
74 resize(copyme.size());
75 for(int s=0;s<_size;s++){
76 _data[s] = copyme[s];
77 }
78 }
79 std::vector<value> toVector(void) const {
80 auto clone =*this;
81 std::vector<value> ret;
82 std::copy(clone.begin(),clone.end(),std::back_inserter(ret));
83 return ret;
84 }
85};
86
88// Coordinate class, maxdims = 8 for now.
90#define GRID_MAX_LATTICE_DIMENSION (8)
91#define GRID_MAX_SIMD (32)
92
93static constexpr int MaxDims = GRID_MAX_LATTICE_DIMENSION;
94
96
97template<class T,int _ndim>
99{
100 if (v.size()!=w.size()) return false;
101 for(int i=0;i<v.size();i++) if ( v[i]!=w[i] ) return false;
102 return true;
103}
104template<class T,int _ndim>
105inline std::ostream & operator<<(std::ostream &os, const AcceleratorVector<T,_ndim> &v)
106{
107 os << "[";
108 for(int s=0;s<v.size();s++) {
109 os << v[s];
110 if( s < (v.size()-1) ){
111 os << " ";
112 }
113 }
114 os << "]";
115 return os;
116}
117
#define accelerator_inline
#define GRID_MAX_LATTICE_DIMENSION
Definition Coordinate.h:90
static constexpr int MaxDims
Definition Coordinate.h:93
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
bool operator==(const AcceleratorVector< T, _ndim > &v, const AcceleratorVector< T, _ndim > &w)
Definition Coordinate.h:98
std::ostream & operator<<(std::ostream &os, const AcceleratorVector< T, _ndim > &v)
Definition Coordinate.h:105
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
std::vector< value > toVector(void) const
Definition Coordinate.h:79
accelerator_inline void push_back(const value &val)
Definition Coordinate.h:69
accelerator_inline void resize(size_type sz)
Definition Coordinate.h:54
accelerator_inline void resize(size_type sz, const value &val)
Definition Coordinate.h:61
accelerator_inline void clear(void)
Definition Coordinate.h:53
accelerator_inline pointer begin(void)
Definition Coordinate.h:65
accelerator_inline const_pointer end(void) const
Definition Coordinate.h:68
accelerator_inline reference operator[](size_type __n)
Definition Coordinate.h:50
accelerator_inline const_reference operator[](size_type __n) const
Definition Coordinate.h:51
accelerator_inline AcceleratorVector(size_type sz, const value &val)
Definition Coordinate.h:72
accelerator_inline size_type size(void) const
Definition Coordinate.h:52
AcceleratorVector(const std::vector< value > &copyme)
Definition Coordinate.h:73
accelerator_inline const_pointer begin(void) const
Definition Coordinate.h:66
accelerator_inline pointer end(void)
Definition Coordinate.h:67
accelerator_inline AcceleratorVector()
Definition Coordinate.h:70
accelerator_inline AcceleratorVector(size_type sz)
Definition Coordinate.h:71