4 #ifndef ROOT_Math_SVector_icc
5 #define ROOT_Math_SVector_icc
34 #ifndef ROOT_Math_SVector
35 #error "Do not use SVector.icc directly. #include \"Math/SVector.h\" instead."
36 #endif // ROOT_Math_SVector
52 template <
class T,
unsigned int D>
53 SVector<T,D>::SVector() {
54 for(
unsigned int i=0; i<D; ++i)
58 template <
class T,
unsigned int D>
60 SVector<T,D>::SVector(
const VecExpr<A,T,D>& rhs) {
64 template <
class T,
unsigned int D>
65 SVector<T,D>::SVector(
const SVector<T,D>& rhs) {
66 for(
unsigned int i=0; i<D; ++i)
67 fArray[i] = rhs.fArray[i];
77 template <
class T,
unsigned int D>
78 template <
class InputIterator>
79 SVector<T,D>::SVector(InputIterator begin, InputIterator end) {
80 assert(begin + D == end);
81 std::copy(begin, end, fArray);
84 template <
class T,
unsigned int D>
85 template <
class InputIterator>
86 SVector<T,D>::SVector(InputIterator begin,
unsigned int size) {
88 std::copy(begin, begin+size, fArray);
93 template <
class T,
unsigned int D>
95 SVector<T,D>::SVector(
const T* a,
unsigned int) {
97 SVector<T,D>::SVector(
const T* a,
unsigned int len) {
100 for(
unsigned int i=0; i<D; ++i)
104 template <
class T,
unsigned int D>
105 SVector<T,D>::SVector(const_iterator ibegin, const_iterator iend) {
106 assert(ibegin + D == iend);
107 std::copy(ibegin, iend, fArray);
114 template <
class T,
unsigned int D>
115 SVector<T,D>::SVector(
const T& a1) {
116 STATIC_CHECK( D == 1,SVector_dimension_not_right);
120 template <
class T,
unsigned int D>
121 SVector<T,D>::SVector(
const T& a1,
const T& a2) {
122 STATIC_CHECK( D == 2,SVector_dimension_not_right);
123 fArray[0] = a1; fArray[1] = a2;
126 template <
class T,
unsigned int D>
127 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3) {
128 STATIC_CHECK( D == 3,SVector_dimension_not_right);
129 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3;
132 template <
class T,
unsigned int D>
133 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4) {
134 STATIC_CHECK( D == 4,SVector_dimension_not_right);
135 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
138 template <
class T,
unsigned int D>
139 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
141 STATIC_CHECK( D == 5,SVector_dimension_not_right);
142 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
146 template <
class T,
unsigned int D>
147 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
148 const T& a5,
const T& a6) {
149 STATIC_CHECK( D == 6,SVector_dimension_not_right);
150 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
151 fArray[4] = a5; fArray[5] = a6;
154 template <
class T,
unsigned int D>
155 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
156 const T& a5,
const T& a6,
const T& a7) {
157 STATIC_CHECK( D == 7,SVector_dimension_not_right);
158 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
159 fArray[4] = a5; fArray[5] = a6; fArray[6] = a7;
162 template <
class T,
unsigned int D>
163 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
164 const T& a5,
const T& a6,
const T& a7,
const T& a8) {
165 STATIC_CHECK( D == 8,SVector_dimension_not_right);
166 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
167 fArray[4] = a5; fArray[5] = a6; fArray[6] = a7; fArray[7] = a8;
170 template <
class T,
unsigned int D>
171 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
172 const T& a5,
const T& a6,
const T& a7,
const T& a8,
174 STATIC_CHECK( D == 9,SVector_dimension_not_right);
175 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
176 fArray[4] = a5; fArray[5] = a6; fArray[6] = a7; fArray[7] = a8;
180 template <
class T,
unsigned int D>
181 SVector<T,D>::SVector(
const T& a1,
const T& a2,
const T& a3,
const T& a4,
182 const T& a5,
const T& a6,
const T& a7,
const T& a8,
183 const T& a9,
const T& a10) {
184 STATIC_CHECK( D == 10,SVector_dimension_not_right);
185 fArray[0] = a1; fArray[1] = a2; fArray[2] = a3; fArray[3] = a4;
186 fArray[4] = a5; fArray[5] = a6; fArray[6] = a7; fArray[7] = a8;
187 fArray[8] = a9; fArray[9] = a10;
193 template <
class T,
unsigned int D>
194 SVector<T,D>& SVector<T,D>::operator=(
const T& a1) {
196 STATIC_CHECK( D == 1,SVector_dimension_not_right);
201 template <
class T,
unsigned int D>
202 SVector<T,D>& SVector<T,D>::operator=(
const SVector<T,D>& rhs) {
203 for(
unsigned int i=0; i<D; ++i)
204 fArray[i] = rhs.fArray[i];
208 template <
class T,
unsigned int D>
210 SVector<T,D>& SVector<T,D>::operator=(
const VecExpr<A,T,D>& rhs) {
211 if (! rhs.IsInUse(fArray) ) {
212 for(
unsigned int i=0; i<D; ++i) {
213 fArray[i] = rhs.apply(i);
219 for(
unsigned int i=0; i<D; ++i) {
220 tmp[i] = rhs.apply(i);
222 for(
unsigned int i=0; i<D; ++i) {
232 template <
class T,
unsigned int D>
233 bool SVector<T,D>::operator==(
const T& rhs)
const {
235 for(
unsigned int i=0; i<D; ++i) {
236 rc = rc && (fArray[i] == rhs);
241 template <
class T,
unsigned int D>
242 bool SVector<T,D>::operator==(
const SVector<T,D>& rhs)
const {
244 for(
unsigned int i=0; i<D; ++i) {
245 rc = rc && (fArray[i] == rhs.apply(i));
250 template <
class T,
unsigned int D>
252 bool SVector<T,D>::operator==(
const VecExpr<A,T,D>& rhs)
const {
254 for(
unsigned int i=0; i<D; ++i) {
255 rc = rc && (fArray[i] == rhs.apply(i));
263 template <
class T,
unsigned int D>
264 inline bool SVector<T,D>::operator!=(
const T& rhs)
const {
265 return !operator==(rhs);
268 template <
class T,
unsigned int D>
269 inline bool SVector<T,D>::operator!=(
const SVector<T,D>& rhs)
const {
270 return !operator==(rhs);
273 template <
class T,
unsigned int D>
275 inline bool SVector<T,D>::operator!=(
const VecExpr<A,T,D>& rhs)
const {
276 return !operator==(rhs);
282 template <
class T,
unsigned int D>
283 bool SVector<T,D>::operator>(
const T& rhs)
const {
285 for(
unsigned int i=0; i<D; ++i) {
286 rc = rc && (fArray[i] > rhs);
291 template <
class T,
unsigned int D>
292 bool SVector<T,D>::operator>(
const SVector<T,D>& rhs)
const {
294 for(
unsigned int i=0; i<D; ++i) {
295 rc = rc && (fArray[i] > rhs.apply(i));
300 template <
class T,
unsigned int D>
302 bool SVector<T,D>::operator>(
const VecExpr<A,T,D>& rhs)
const {
304 for(
unsigned int i=0; i<D; ++i) {
305 rc = rc && (fArray[i] > rhs.apply(i));
313 template <
class T,
unsigned int D>
314 bool SVector<T,D>::operator<(
const T& rhs)
const {
316 for(
unsigned int i=0; i<D; ++i) {
317 rc = rc && (fArray[i] < rhs);
322 template <
class T,
unsigned int D>
323 bool SVector<T,D>::operator<(
const SVector<T,D>& rhs)
const {
325 for(
unsigned int i=0; i<D; ++i) {
326 rc = rc && (fArray[i] < rhs.apply(i));
331 template <
class T,
unsigned int D>
333 bool SVector<T,D>::operator<(
const VecExpr<A,T,D>& rhs)
const {
335 for(
unsigned int i=0; i<D; ++i) {
336 rc = rc && (fArray[i] < rhs.apply(i));
345 template <
class T,
unsigned int D>
347 SVector<T,D>& SVector<T,D>::operator+=(
const A& rhs) {
348 return operator=(*
this + rhs);
351 template <
class T,
unsigned int D>
353 SVector<T,D>& SVector<T,D>::operator-=(
const A& rhs) {
355 return operator=(*
this - rhs);
358 template <
class T,
unsigned int D>
360 SVector<T,D>& SVector<T,D>::operator*=(
const A& rhs) {
362 return operator=(*
this * rhs);
365 template <
class T,
unsigned int D>
367 SVector<T,D>& SVector<T,D>::operator/=(
const A& rhs) {
369 return operator=(*
this / rhs);
373 template <
class T,
unsigned int D>
374 SVector<T,D>& SVector<T,D>::operator+=(
const T& rhs) {
375 for(
unsigned int i=0; i<D; ++i) {
381 template <
class T,
unsigned int D>
382 SVector<T,D>& SVector<T,D>::operator+=(
const SVector<T,D>& rhs) {
383 for(
unsigned int i=0; i<D; ++i) {
384 fArray[i] += rhs.apply(i);
390 template <
class T,
unsigned int D>
392 SVector<T,D>& SVector<T,D>::operator+=(
const VecExpr<A,T,D>& rhs) {
393 for(
unsigned int i=0; i<D; ++i) {
394 fArray[i] += rhs.apply(i);
402 template <
class T,
unsigned int D>
403 SVector<T,D>& SVector<T,D>::operator-=(
const T& rhs) {
404 for(
unsigned int i=0; i<D; ++i) {
410 template <
class T,
unsigned int D>
411 SVector<T,D>& SVector<T,D>::operator-=(
const SVector<T,D>& rhs) {
412 for(
unsigned int i=0; i<D; ++i) {
413 fArray[i] -= rhs.apply(i);
418 template <
class T,
unsigned int D>
420 SVector<T,D>& SVector<T,D>::operator-=(
const VecExpr<A,T,D>& rhs) {
421 for(
unsigned int i=0; i<D; ++i) {
422 fArray[i] -= rhs.apply(i);
430 template <
class T,
unsigned int D>
431 SVector<T,D>& SVector<T,D>::operator*=(
const T& rhs) {
432 for(
unsigned int i=0; i<D; ++i) {
438 template <
class T,
unsigned int D>
440 SVector<T,D>& SVector<T,D>::operator*=(
const VecExpr<A,T,D>& rhs) {
441 for(
unsigned int i=0; i<D; ++i) {
442 fArray[i] *= rhs.apply(i);
450 template <
class T,
unsigned int D>
451 SVector<T,D>& SVector<T,D>::operator/=(
const SVector<T,D>& rhs) {
452 for(
unsigned int i=0; i<D; ++i) {
453 fArray[i] /= rhs.apply(i);
458 template <
class T,
unsigned int D>
460 SVector<T,D>& SVector<T,D>::operator/=(
const VecExpr<A,T,D>& rhs) {
461 for(
unsigned int i=0; i<D; ++i) {
462 fArray[i] /= rhs.apply(i);
467 template <
class T,
unsigned int D>
468 SVector<T,D>& SVector<T,D>::operator/=(
const T& rhs) {
469 for(
unsigned int i=0; i<D; ++i) {
479 template <
class T,
unsigned int D>
480 SVector<T,D>& SVector<T,D>::Unit() {
481 const T len = Mag(*
this);
482 for(
unsigned int i=0; i<D; ++i) {
491 template <
class T,
unsigned int D>
492 template <
unsigned int D2>
493 SVector<T,D>& SVector<T,D>::Place_at(
const SVector<T,D2>& rhs,
unsigned int row) {
498 for(
unsigned int i=row, j=0; j<D2; ++i,++j)
499 fArray[i] = rhs.apply(j);
508 template <
class T,
unsigned int D>
509 template <
class A,
unsigned int D2>
510 SVector<T,D>& SVector<T,D>::Place_at(
const VecExpr<A,T,D2>& rhs,
unsigned int row) {
514 for(
unsigned int i=row, j=0; j<D2; ++i,++j)
515 fArray[i] = rhs.apply(j);
523 template <
class T,
unsigned int D>
524 std::ostream& SVector<T,D>::Print(std::ostream& os)
const {
525 const std::ios_base::fmtflags prevFmt = os.setf(std::ios::right,std::ios::adjustfield);
528 for (
unsigned int i = 0; i < D; ++i ) {
530 if (i != D-1) os <<
", ";
532 if (prevFmt != os.flags() ) os.setf(prevFmt, std::ios::adjustfield);
539 template <
class T,
unsigned int D>
540 inline T SVector<T,D>::apply(
unsigned int i)
const {
return fArray[i]; }
542 template <
class T,
unsigned int D>
543 inline const T* SVector<T,D>::Array()
const {
return fArray; }
545 template <
class T,
unsigned int D>
546 inline T* SVector<T,D>::Array() {
return fArray; }
552 template <
class T,
unsigned int D>
553 inline T* SVector<T,D>::begin() {
return fArray; }
555 template <
class T,
unsigned int D>
556 inline const T* SVector<T,D>::begin()
const {
return fArray; }
558 template <
class T,
unsigned int D>
559 inline T* SVector<T,D>::end() {
return fArray + Dim(); }
561 template <
class T,
unsigned int D>
562 inline const T* SVector<T,D>::end()
const {
return fArray + Dim(); }
564 template <
class T,
unsigned int D>
565 template <
class InputIterator>
566 void SVector<T,D>::SetElements(InputIterator ibegin, InputIterator iend) {
568 assert( ibegin + D == iend);
569 std::copy(ibegin, iend, fArray);
572 template <
class T,
unsigned int D>
573 template <
class InputIterator>
574 void SVector<T,D>::SetElements(InputIterator ibegin,
unsigned int size) {
577 std::copy(ibegin, ibegin+size, fArray);
584 template <
class T,
unsigned int D>
585 inline const T& SVector<T,D>::operator[](
unsigned int i)
const {
return fArray[i]; }
587 template <
class T,
unsigned int D>
588 inline const T& SVector<T,D>::operator()(
unsigned int i)
const {
return fArray[i]; }
590 template <
class T,
unsigned int D>
591 inline T& SVector<T,D>::operator[](
unsigned int i) {
return fArray[i]; }
593 template <
class T,
unsigned int D>
594 inline T& SVector<T,D>::operator()(
unsigned int i) {
return fArray[i]; }
598 template <
class T,
unsigned int D>
599 inline const T& SVector<T,D>::At(
unsigned int i)
const {
604 template <
class T,
unsigned int D>
605 inline T& SVector<T,D>::At(
unsigned int i) {
613 template <
class T,
unsigned int D>
614 template <
class SubVector>
615 SubVector SVector<T,D>::Sub(
unsigned int row)
const {
617 STATIC_CHECK( SubVector::kSize <= D,SVector_dimension_too_small);
619 assert(row + SubVector::kSize <= D);
623 for(
unsigned int i=0; i < SubVector::kSize; ++i) {
624 tmp[i] = fArray[i+row];
630 template <
class T,
unsigned int D>
631 bool SVector<T,D>::IsInUse(
const T * p)
const {
639 template <
class T,
unsigned int D>
640 inline std::ostream& operator<<(std::ostream& os, const SVector<T,D>& rhs) {
641 return rhs.Print(os);