OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
20template<class T, unsigned Length>
21class vec
22{
23public:
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*);
40private:
41 T Ptr[Length];
42};
43
45
46template<class T, unsigned Length>
47inline
49{
50 CTAssert(Length==1);
51 Ptr[0] = v0;
52}
53
54template<class T, unsigned Length>
55inline
57{
58 CTAssert(Length==2);
59 Ptr[0] = v0;
60 Ptr[1] = v1;
61}
62
63template<class T, unsigned Length>
64inline
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//
79template<class T, unsigned Length>
80inline T
81vec<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 & get_iter(OutputIterator o)
Definition: Message.h:511
Message & put(const T &val)
Definition: Message.h:406
Definition: Vec.h:22
vec(T v0)
Definition: Vec.h:48
T & operator[](unsigned d)
Definition: Vec.h:28
const T & operator[](unsigned d) const
Definition: Vec.h:29
vec(T v0, T v1)
Definition: Vec.h:56
vec()
Definition: Vec.h:24
Message & putMessage(Message &m)
Definition: Vec.h:30
Message & getMessage(Message &m)
Definition: Vec.h:34
static T dot(const T *, const T *)
Definition: Vec.h:81
T Ptr[Length]
Definition: Vec.h:41
vec(T v0, T v1, T v2)
Definition: Vec.h:65