OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Vec.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef VEC_H
12 #define VEC_H
13 
14 // include files
15 #include "Message/Message.h"
16 #include "Utility/PAssert.h"
17 
19 
20 template<class T, unsigned Length>
21 class vec
22 {
23 public:
24  vec() {}
25  vec(T v0);
26  vec(T v0, T v1);
27  vec(T v0, T v1, T v2);
28  T& operator[](unsigned d) { return Ptr[d]; }
29  const T& operator[](unsigned d) const { return Ptr[d]; }
31  m.put(Ptr, Ptr + Length);
32  return m;
33  }
35  m.get_iter(Ptr);
36  return m;
37  }
38 
39  static T dot(const T*,const T*);
40 private:
41  T Ptr[Length];
42 };
43 
45 
46 template<class T, unsigned Length>
47 inline
49 {
50  CTAssert(Length==1);
51  Ptr[0] = v0;
52 }
53 
54 template<class T, unsigned Length>
55 inline
57 {
58  CTAssert(Length==2);
59  Ptr[0] = v0;
60  Ptr[1] = v1;
61 }
62 
63 template<class T, unsigned Length>
64 inline
65 vec<T,Length>::vec(T v0, T v1, T v2)
66 {
67  CTAssert(Length==3);
68  Ptr[0] = v0;
69  Ptr[1] = v1;
70  Ptr[2] = v2;
71 }
72 
74 
75 //
76 // Define a global function for taking the dot product between two
77 // short arrays of objects of type T.
78 //
79 template<class T, unsigned Length>
80 inline T
81 vec<T,Length>::dot(const T* l, const T* r)
82 {
83  T ret = l[0]*r[0];
84  for (unsigned int i=1; i<Length; ++i)
85  ret += l[i]*r[i];
86  return ret;
87 }
88 
90 
91 #endif // VEC_H
92 
93 /***************************************************************************
94  * $RCSfile: Vec.h,v $ $Author: adelmann $
95  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $
96  * IPPL_VERSION_ID: $Id: Vec.h,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $
97  ***************************************************************************/
#define CTAssert(c)
Definition: PAssert.h:35
Message & put(const T &val)
Definition: Message.h:406
Message & get_iter(OutputIterator o)
Definition: Message.h:511
Definition: Vec.h:22
vec(T v0)
Definition: Vec.h:48
vec(T v0, T v1)
Definition: Vec.h:56
vec()
Definition: Vec.h:24
static T dot(const T *, const T *)
Definition: Vec.h:81
T Ptr[Length]
Definition: Vec.h:41
Message & getMessage(Message &m)
Definition: Vec.h:34
Message & putMessage(Message &m)
Definition: Vec.h:30
T & operator[](unsigned d)
Definition: Vec.h:28
const T & operator[](unsigned d) const
Definition: Vec.h:29
vec(T v0, T v1, T v2)
Definition: Vec.h:65