ROOT
6.06/09
Reference Guide
ROOT Home Page
Main Page
Related Pages
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
math
vc
examples
polarcoord
main.cpp
Go to the documentation of this file.
1
/* This file is part of the Vc library.
2
3
Copyright (C) 2009-2012 Matthias Kretz <kretz@kde.org>
4
5
Permission to use, copy, modify, and distribute this software
6
and its documentation for any purpose and without fee is hereby
7
granted, provided that the above copyright notice appear in all
8
copies and that both that the copyright notice and this
9
permission notice and warranty disclaimer appear in supporting
10
documentation, and that the name of the author not be used in
11
advertising or publicity pertaining to distribution of the
12
software without specific, written prior permission.
13
14
The author disclaim all warranties with regard to this
15
software, including all implied warranties of merchantability
16
and fitness. In no event shall the author be liable for any
17
special, indirect or consequential damages or any damages
18
whatsoever resulting from loss of use, data or profits, whether
19
in an action of contract, negligence or other tortious action,
20
arising out of or in connection with the use or performance of
21
this software.
22
23
*/
24
25
//! [includes]
26
#include <Vc/Vc>
27
#include <iostream>
28
#include <iomanip>
29
30
using
Vc::float_v
;
31
//! [includes]
32
33
//! [memory allocation]
34
int
main
()
35
{
36
// allocate memory for our initial x and y coordinates. Note that you can also put it into a
37
// normal float C-array but that you then must ensure alignment to Vc::VectorAlignment!
38
Vc::Memory<float_v, 1000>
x_mem;
39
Vc::Memory<float_v, 1000>
y_mem;
40
Vc::Memory<float_v, 1000>
r_mem;
41
Vc::Memory<float_v, 1000>
phi_mem;
42
//! [memory allocation]
43
44
//! [random init]
45
// fill the memory with values from -1.f to 1.f
46
for
(
size_t
i = 0; i < x_mem.
vectorsCount
(); ++i) {
47
x_mem.
vector
(i) =
float_v::Random
() * 2.f - 1.f;
48
y_mem.
vector
(i) =
float_v::Random
() * 2.f - 1.f;
49
}
50
//! [random init]
51
52
//! [conversion]
53
// calculate the polar coordinates for all coordinates and overwrite the euclidian coordinates
54
// with the result
55
for
(
size_t
i = 0; i < x_mem.
vectorsCount
(); ++i) {
56
const
float_v
x
= x_mem.
vector
(i);
57
const
float_v
y
= y_mem.
vector
(i);
58
59
r_mem.
vector
(i) =
Vc::sqrt
(x * x + y * y);
60
float_v
phi =
Vc::atan2
(y, x) * 57.295780181884765625f;
// 180/pi
61
phi(phi < 0.
f
) += 360.f;
62
phi_mem.
vector
(i) = phi;
63
}
64
//! [conversion]
65
66
//! [output]
67
// print the results
68
for
(
size_t
i = 0; i < x_mem.
entriesCount
(); ++i) {
69
std::cout << std::setw(3) << i <<
": "
;
70
std::cout << std::setw(10) << x_mem[i] <<
", "
<< std::setw(10) << y_mem[i] <<
" -> "
;
71
std::cout << std::setw(10) << r_mem[i] <<
", "
<< std::setw(10) << phi_mem[i] <<
'\n'
;
72
}
73
74
return
0;
75
}
76
//! [output]
ROOT::Vc::Memory::vectorsCount
_VC_CONSTEXPR size_t vectorsCount() const
Definition:
memory.h:169
ROOT::Vc::Memory::entriesCount
_VC_CONSTEXPR size_t entriesCount() const
Definition:
memory.h:163
sqrt
double sqrt(double)
x
Double_t x[n]
Definition:
legend1.C:17
ROOT::Vc::MemoryBase< V, Memory< V, Size1, Size2 >, 2, Memory< V, Size2 > >::vector
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlag > vector(size_t i)
Definition:
memorybase.h:310
ROOT::Vc::Memory
A helper class for fixed-size two-dimensional arrays.
Definition:
memory.h:120
f
double f(double x)
Definition:
testIntegration.cxx:12
Random
void Random()
Definition:
utils.cpp:154
atan2
double atan2(double, double)
main
int main(int argc, char **argv)
Main program.
Definition:
main.cpp:22
y
Double_t y[n]
Definition:
legend1.C:17
ROOT::Vc::AVX::float_v
Vector< float > float_v
Definition:
vector.h:417