Commit a81d396e670b4f7dcbd07a63ec12df66f69bae20

Authored by Pavel Govyadinov
2 parents 80d3850d 321ff17a

test2

stim/math/mathvec.h
... ... @@ -19,72 +19,71 @@ struct vec : public std::vector<T>
19 19 using std::vector<T>::at;
20 20 using std::vector<T>::resize;
21 21 using std::vector<T>::push_back;
22   - CUDA_CALLABLE vec(){
  22 + vec(){
23 23  
24 24 }
25 25  
26   -// //efficiency constructors, makes construction easier for 1D-4D vectors
27   -// CUDA_CALLABLE vec(T rhs)
28   -// {
29   -// resize(1, rhs);
30   -// cerr << " Created a vector " << endl;
31   -// //for(int i=0; i<N; i++)
32   -// // v[i] = rhs;
33   -// }
34   -
35   - CUDA_CALLABLE vec(int s)
  26 + /// Create a vector with a set dimension d
  27 + vec(int d)
36 28 {
37   - resize(s,0);
38   - }
  29 + resize(d,0);
  30 + }
39 31  
40   - CUDA_CALLABLE vec(T x, T y)
  32 +
  33 +// //efficiency constructors, makes construction easier for 1D-4D vectors
  34 + vec(T x, T y)
41 35 {
42   - push_back(x);
43   - push_back(y);
  36 + resize(2, 0);
  37 + at(0) = x;
  38 + at(1) = y;
44 39 }
45   - CUDA_CALLABLE vec(T x, T y, T z)
  40 + vec(T x, T y, T z)
46 41 {
47   - push_back(x);
48   - push_back(y);
49   - push_back(z);
  42 + resize(3, 0);
  43 + at(0) = x;
  44 + at(1) = y;
  45 + at(2) = z;
50 46 }
51   - CUDA_CALLABLE vec(T x, T y, T z, T w)
  47 + vec(T x, T y, T z, T w)
52 48 {
53   - push_back(x);
54   - push_back(y);
55   - push_back(z);
56   - push_back(w);
  49 + resize(4, 0);
  50 + at(0) = x;
  51 + at(1) = y;
  52 + at(2) = z;
  53 + at(3) = w;
57 54 }
58 55  
59 56  
60 57  
61 58 //copy constructor
62   - CUDA_CALLABLE vec( const vec<T>& other){
  59 + vec( const vec<T>& other){
63 60 unsigned int N = other.size();
64 61 for(int i=0; i<N; i++)
65 62 push_back(other[i]);
66 63 }
67 64  
68   - CUDA_CALLABLE vec<T> push(T x)
  65 + //I'm not sure what these were doing here.
  66 + //Keep them now, we'll worry about it later.
  67 + vec<T> push(T x)
69 68 {
70 69 push_back(x);
71 70 return *this;
72 71 }
73 72  
74   - CUDA_CALLABLE vec<T> push(T x, T y)
  73 + vec<T> push(T x, T y)
75 74 {
76 75 push_back(x);
77 76 push_back(y);
78 77 return *this;
79 78 }
80   - CUDA_CALLABLE vec<T> push(T x, T y, T z)
  79 + vec<T> push(T x, T y, T z)
81 80 {
82 81 push_back(x);
83 82 push_back(y);
84 83 push_back(z);
85 84 return *this;
86 85 }
87   - CUDA_CALLABLE vec<T> push(T x, T y, T z, T w)
  86 + vec<T> push(T x, T y, T z, T w)
88 87 {
89 88 push_back(x);
90 89 push_back(y);
... ... @@ -92,8 +91,10 @@ struct vec : public std::vector&lt;T&gt;
92 91 push_back(w);
93 92 return *this;
94 93 }
  94 +
  95 + /// Casting operator. Creates a new vector with a new type U.
95 96 template< typename U >
96   - CUDA_CALLABLE operator vec<U>(){
  97 + operator vec<U>(){
97 98 unsigned int N = size();
98 99 vec<U> result;
99 100 for(int i=0; i<N; i++)
... ... @@ -102,10 +103,9 @@ struct vec : public std::vector&lt;T&gt;
102 103 return result;
103 104 }
104 105  
105   - //template<class U>
106   - //friend vec<U, N>::operator vec<T, N>();
107 106  
108   - CUDA_CALLABLE T len() const
  107 + /// computes the Euclidean length of the vector
  108 + T len() const
109 109 {
110 110 unsigned int N = size();
111 111  
... ... @@ -119,10 +119,10 @@ struct vec : public std::vector&lt;T&gt;
119 119  
120 120 }
121 121  
122   - CUDA_CALLABLE vec<T> cart2sph() const
  122 + /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi])
  123 + vec<T> cart2sph() const
123 124 {
124   - //convert the vector from cartesian to spherical coordinates
125   - //x, y, z -> r, theta, phi (where theta = 0 to 2*pi)
  125 +
126 126  
127 127 vec<T> sph;
128 128 sph.push_back(std::sqrt(at(0)*at(0) + at(1)*at(1) + at(2)*at(2)));
... ... @@ -136,11 +136,9 @@ struct vec : public std::vector&lt;T&gt;
136 136 return sph;
137 137 }
138 138  
139   - CUDA_CALLABLE vec<T> sph2cart() const
  139 + /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi])
  140 + vec<T> sph2cart() const
140 141 {
141   - //convert the vector from cartesian to spherical coordinates
142   - //r, theta, phi -> x, y, z (where theta = 0 to 2*pi)
143   -
144 142 vec<T> cart;
145 143 cart.push_back(at(0) * std::cos(at(1)) * std::sin(at(2)));
146 144 cart.push_back(at(0) * std::sin(at(1)) * std::sin(at(2)));
... ... @@ -149,7 +147,8 @@ struct vec : public std::vector&lt;T&gt;
149 147 return cart;
150 148 }
151 149  
152   - CUDA_CALLABLE vec<T> norm() const
  150 + /// Computes the normalized vector (where each coordinate is divided by the L2 norm)
  151 + vec<T> norm() const
153 152 {
154 153 unsigned int N = size();
155 154  
... ... @@ -168,22 +167,27 @@ struct vec : public std::vector&lt;T&gt;
168 167 return result;
169 168 }
170 169  
171   - CUDA_CALLABLE vec<T> cross(const vec<T> rhs) const
  170 + /// Computes the cross product of a 3-dimensional vector
  171 + vec<T> cross(const vec<T> rhs) const
172 172 {
173   - vec<T> result;
  173 + if(size() != 3)
  174 + std::cout<<"Error in stim::mathvec::cross() - the vector must have 3 components"<<std::endl;
  175 +
  176 + vec<T> result(3);
174 177  
175 178 //compute the cross product (only valid for 3D vectors)
176   - result.push_back(at(1) * rhs[2] - at(2) * rhs[1]);
177   - result.push_back(at(2) * rhs[0] - at(0) * rhs[2]);
178   - result.push_back(at(0) * rhs[1] - at(1) * rhs[0]);
  179 + result[0] = (at(1) * rhs[2] - at(2) * rhs[1]);
  180 + result[1] = (at(2) * rhs[0] - at(0) * rhs[2]);
  181 + result[2] = (at(0) * rhs[1] - at(1) * rhs[0]);
179 182  
180 183 return result;
181 184 }
182 185  
183   - CUDA_CALLABLE T dot(vec<T> rhs) const
  186 + /// Compute the Euclidean inner (dot) product
  187 + T dot(vec<T> rhs) const
184 188 {
185 189 T result = (T)0;
186   - unsigned int N = size();
  190 + unsigned int N = size();
187 191 for(int i=0; i<N; i++)
188 192 result += at(i) * rhs[i];
189 193  
... ... @@ -191,70 +195,98 @@ struct vec : public std::vector&lt;T&gt;
191 195  
192 196 }
193 197  
194   - //arithmetic
195   - CUDA_CALLABLE vec<T> operator+(vec<T> rhs) const
196   - {
197   - vec<T> result;
  198 + /// Arithmetic addition operator
198 199  
  200 + /// @param rhs is the right-hand-side operator for the addition
  201 + vec<T> operator+(vec<T> rhs) const
  202 + {
199 203 unsigned int N = size();
  204 + vec<T> result(N);
  205 +
200 206 for(int i=0; i<N; i++)
201   - result.push_back(at(i) + rhs[i]);
  207 + result[i] = at(i) + rhs[i];
202 208  
203 209 return result;
204 210 }
205   - CUDA_CALLABLE vec<T> operator+(T rhs) const
  211 +
  212 + /// Arithmetic addition to a scalar
  213 +
  214 + /// @param rhs is the right-hand-side operator for the addition
  215 + vec<T> operator+(T rhs) const
206 216 {
207   - vec<T> result;
208 217 unsigned int N = size();
  218 +
  219 + vec<T> result(N);
209 220 for(int i=0; i<N; i++)
210   - result.push_back(at(i) + rhs);
  221 + result[i] = at(i) + rhs;
211 222  
212 223 return result;
213 224 }
214   - CUDA_CALLABLE vec<T> operator-(vec<T> rhs) const
215   - {
216   - vec<T> result;
217 225  
  226 + /// Arithmetic subtraction operator
  227 +
  228 + /// @param rhs is the right-hand-side operator for the subtraction
  229 + vec<T> operator-(vec<T> rhs) const
  230 + {
218 231 unsigned int N = size();
  232 +
  233 + vec<T> result(N);
  234 +
219 235 for(int i=0; i<N; i++)
220   - result.push_back(at(i) - rhs[i]);
  236 + result[i] = at(i) - rhs[i];
221 237  
222 238 return result;
223 239 }
224   - CUDA_CALLABLE vec<T> operator*(T rhs) const
225   - {
226   - vec<T> result;
227 240  
  241 + /// Arithmetic scalar multiplication operator
  242 +
  243 + /// @param rhs is the right-hand-side operator for the subtraction
  244 + vec<T> operator*(T rhs) const
  245 + {
228 246 unsigned int N = size();
  247 +
  248 + vec<T> result(N);
  249 +
229 250 for(int i=0; i<N; i++)
230   - result.push_back(at(i) * rhs);
  251 + result[i] = at(i) * rhs;
231 252  
232 253 return result;
233 254 }
234   - CUDA_CALLABLE vec<T> operator/(T rhs) const
235   - {
236   - vec<T> result;
237 255  
  256 + /// Arithmetic scalar division operator
  257 +
  258 + /// @param rhs is the right-hand-side operator for the subtraction
  259 + vec<T> operator/(T rhs) const
  260 + {
238 261 unsigned int N = size();
  262 +
  263 + vec<T> result(N);
  264 +
239 265 for(int i=0; i<N; i++)
240   - result.push_back(at(i) / rhs);
  266 + result[i] = at(i) / rhs;
241 267  
242 268 return result;
243 269 }
244   - CUDA_CALLABLE vec<T> operator*=(T rhs){
  270 +
  271 + /// Multiplication by a scalar, followed by assignment
  272 + vec<T> operator*=(T rhs){
245 273  
246 274 unsigned int N = size();
247 275 for(int i=0; i<N; i++)
248 276 at(i) = at(i) * rhs;
249 277 return *this;
250 278 }
251   - CUDA_CALLABLE vec<T> operator+=(vec<T> rhs){
  279 +
  280 + /// Addition and assignment
  281 + vec<T> operator+=(vec<T> rhs){
252 282 unsigned int N = size();
253 283 for(int i=0; i<N; i++)
254 284 at(i) += rhs[i];
255 285 return *this;
256 286 }
257   - CUDA_CALLABLE vec<T> & operator=(T rhs){
  287 +
  288 + /// Assign a scalar to all values
  289 + vec<T> & operator=(T rhs){
258 290  
259 291 unsigned int N = size();
260 292 for(int i=0; i<N; i++)
... ... @@ -262,8 +294,9 @@ struct vec : public std::vector&lt;T&gt;
262 294 return *this;
263 295 }
264 296  
  297 + /// Casting and assignment
265 298 template<typename Y>
266   - CUDA_CALLABLE vec<T> & operator=(vec<Y> rhs){
  299 + vec<T> & operator=(vec<Y> rhs){
267 300 unsigned int N = rhs.size();
268 301 resize(N);
269 302  
... ... @@ -271,19 +304,23 @@ struct vec : public std::vector&lt;T&gt;
271 304 at(i) = rhs[i];
272 305 return *this;
273 306 }
274   - //unary minus
275   - CUDA_CALLABLE vec<T> operator-() const{
276   - vec<T> r;
277 307  
278   - //negate the vector
  308 + /// Unary minus (returns the negative of the vector)
  309 + vec<T> operator-() const{
  310 +
279 311 unsigned int N = size();
  312 +
  313 + vec<T> r(N);
  314 +
  315 + //negate the vector
280 316 for(int i=0; i<N; i++)
281   - r.push_back(-at(i));
  317 + r[i] = -at(i);
282 318  
283 319 return r;
284 320 }
285 321  
286 322  
  323 + /// Outputs the vector as a string
287 324 std::string str() const
288 325 {
289 326 std::stringstream ss;
... ... @@ -315,17 +352,13 @@ std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, stim::vec&lt;T&gt; v)
315 352 }
316 353  
317 354  
318   -
  355 +/// Multiply a vector by a constant when the vector is on the right hand side
319 356 template <typename T>
320   -CUDA_CALLABLE stim::vec<T> operator*(T lhs, stim::vec<T> rhs)
  357 +stim::vec<T> operator*(T lhs, stim::vec<T> rhs)
321 358 {
322 359 stim::vec<T> r;
323 360  
324 361 return rhs * lhs;
325 362 }
326 363  
327   -//#if __GNUC__ > 3 && __GNUC_MINOR__ > 7
328   -//template<class T, int N> using rtsVector = rts::vector<T, N>;
329   -//#endif
330   -
331 364 #endif
... ...
stim/math/spharmonics.h
... ... @@ -100,7 +100,7 @@ public:
100 100 /// @param sph_pts is a list of points in spherical coordinates (theta, phi) where theta = [0, 2pi] and phi = [0, pi]
101 101 /// @param l is the maximum degree of the spherical harmonic function
102 102 /// @param m is the maximum order
103   - void pdf(std::vector<stim::vec<double>> sph_pts, unsigned int l, int m){
  103 + void pdf(std::vector<stim::vec<double> > sph_pts, unsigned int l, int m){
104 104  
105 105 mcBegin( l, m ); //begin spherical harmonic sampling
106 106  
... ...
stim/visualization/gl_spharmonics.h
... ... @@ -14,6 +14,8 @@ template &lt;typename T&gt;
14 14 class gl_spharmonics : public spharmonics<T>{
15 15  
16 16 protected:
  17 + using spharmonics<T>::C;
  18 + using spharmonics<T>::SH;
17 19  
18 20 T* func; //stores the raw function data (samples at each point)
19 21  
... ... @@ -184,4 +186,4 @@ public:
184 186  
185 187  
186 188  
187   -#endif
188 189 \ No newline at end of file
  190 +#endif
... ...