ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 /* This file is part of the Vc project
2  Copyright (C) 2009-2010 Matthias Kretz <kretz@kde.org>
3 
4  Permission to use, copy, modify, and distribute this software
5  and its documentation for any purpose and without fee is hereby
6  granted, provided that the above copyright notice appear in all
7  copies and that both that the copyright notice and this
8  permission notice and warranty disclaimer appear in supporting
9  documentation, and that the name of the author not be used in
10  advertising or publicity pertaining to distribution of the
11  software without specific, written prior permission.
12 
13  The author disclaim all warranties with regard to this
14  software, including all implied warranties of merchantability
15  and fitness. In no event shall the author be liable for any
16  special, indirect or consequential damages or any damages
17  whatsoever resulting from loss of use, data or profits, whether
18  in an action of contract, negligence or other tortious action,
19  arising out of or in connection with the use or performance of
20  this software.
21 
22 */
23 
24 #include <Vc/Vc>
25 #include <Vc/IO>
26 #include <iostream>
27 #include <iomanip>
28 
29 template<typename T, unsigned int Size> class Matrix;
30 template<typename T, unsigned int Size> std::ostream &operator<<(std::ostream &, const Matrix<T, Size> &);
31 
32 template<typename T, unsigned int Size>
33 class Matrix
34 {
35  friend std::ostream &operator<< <>(std::ostream &, const Matrix<T, Size> &);
36  private:
37  typedef Vc::Vector<T> V;
39  public:
40  Matrix &operator=(const T &val) {
41  V vec(val);
42  for (unsigned int i = 0; i < m_mem.vectorsCount(); ++i) {
43  m_mem.vector(i) = vec;
44  }
45  return *this;
46  }
47 
48  Matrix &operator+=(const Matrix &rhs) {
49  for (unsigned int i = 0; i < m_mem.vectorsCount(); ++i) {
50  V v1(m_mem.vector(i));
51  v1 += V(rhs.m_mem.vector(i));
52  m_mem.vector(i) = v1;
53  }
54  return *this;
55  }
56 };
57 
58 template<typename T, unsigned int Size>
59 std::ostream &operator<<(std::ostream &out, const Matrix<T, Size> &m)
60 {
61  for (unsigned int i = 0; i < Size; ++i) {
62  std::cout << "[" << std::setw(6) << m.m_mem[i * Size];
63  for (unsigned int j = 1; j < Size; ++j) {
64  std::cout << std::setw(6) << m.m_mem[i * Size + j];
65  }
66  std::cout << " ]\n";
67  }
68  return out;
69 }
70 
71 int main()
72 {
73  Matrix<float, 15> m1;
74  m1 = 1.f;
75  Matrix<float, 15> m2;
76  m2 = 2.f;
77  m1 += m2;
78  std::cout << m1 << std::endl;
79  return 0;
80 }
const Double_t * v1
Definition: TArcBall.cxx:33
const char * Size
Definition: TXMLSetup.cxx:56
TTree * T
char * out
Definition: TBase64.cxx:29
TMarker * m
Definition: textangle.C:8
int main(int argc, char **argv)
Main program.
Definition: main.cpp:22
Binding & operator=(OUT(*fun)(void))