Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
387cf9bb
Commit
387cf9bb
authored
Mar 10, 2021
by
niklas.baumgarten
Browse files
removing Mean an Variance, using RVector, CVector
parent
60eedc6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
mlmc/src/basics/Utilities.cpp
View file @
387cf9bb
#include <RVector.hpp>
#include <CVector.hpp>
#include "Utilities.hpp"
...
...
@@ -41,7 +43,7 @@ void fft(int N, fftw_complex *in, fftw_complex *out) {
fftw_cleanup
();
}
void
fft
(
std
::
vector
<
std
::
complex
<
double
>>
&
in
,
std
::
vector
<
std
::
complex
<
double
>>
&
out
)
{
void
fft
(
const
CVector
&
in
,
CVector
&
out
)
{
int
N
=
in
.
size
();
fftw_complex
in_arr
[
N
],
out_arr
[
N
];
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
...
...
@@ -55,10 +57,10 @@ void fft(std::vector<std::complex<double>> &in, std::vector<std::complex<double>
}
}
void
fft
(
const
std
::
vector
<
double
>
&
in
,
std
::
vector
<
double
>
&
out
)
{
void
fft
(
const
RVector
&
in
,
RVector
&
out
)
{
int
N
=
in
.
size
();
std
::
vector
<
std
::
complex
<
double
>>
in_complex
;
std
::
vector
<
std
::
complex
<
double
>>
out_complex
;
CVector
in_complex
;
CVector
out_complex
;
in_complex
.
resize
(
N
);
out_complex
.
resize
(
N
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
...
...
mlmc/src/basics/Utilities.hpp
View file @
387cf9bb
#ifndef TOOLS_HPP
#define TOOLS_HPP
#include "RVector.hpp"
#include "CVector.hpp"
#include "RMatrix.hpp"
#inlcude "CMatrix.hpp"
#include <vector>
#include <string>
#include <math.h>
#include <complex>
#include <fftw3.h>
template
<
typename
T
>
std
::
string
vec2str
(
std
::
vector
<
T
>
vec
);
template
<
typename
T
>
T
Mean
(
const
std
::
vector
<
T
>
&
vec
)
{
T
mean
=
0.0
;
for
(
auto
const
&
value
:
vec
)
mean
+=
value
;
return
mean
/
T
(
vec
.
size
());
}
template
<
typename
T
>
T
Mean
(
const
std
::
vector
<
std
::
vector
<
double
>>
&
vec
)
{
T
mean
=
0.0
;
for
(
auto
const
&
value_vec
:
vec
)
for
(
auto
const
&
value
:
value_vec
)
mean
+=
value
;
return
mean
/
vec
.
size
();
}
template
<
typename
T
>
T
Variance
(
const
std
::
vector
<
T
>
&
vec
)
{
T
sqrs
=
0.0
;
for
(
auto
const
&
value
:
vec
)
sqrs
+=
std
::
pow
(
value
,
2
);
return
sqrs
/
T
(
vec
.
size
())
-
std
::
pow
(
Mean
(
vec
),
2
);
}
template
<
typename
T
>
double
Variance
(
const
std
::
vector
<
std
::
vector
<
T
>>
&
vec
)
{
double
sqrs
=
0.0
;
for
(
auto
const
&
value_vec
:
vec
)
for
(
auto
const
&
value
:
value_vec
)
sqrs
+=
std
::
pow
(
value
,
2
);
return
sqrs
/
vec
.
size
()
-
std
::
pow
(
Mean
(
vec
),
2
);
}
void
fft
(
int
N
,
fftw_complex
*
in
,
fftw_complex
*
out
);
void
fft
(
std
::
vector
<
std
::
complex
<
double
>>
&
in
,
std
::
vector
<
std
::
complex
<
double
>>
&
out
);
void
fft
(
const
CVector
&
in
,
CVector
&
out
);
void
fft
(
const
std
::
vector
<
double
>
&
in
,
std
::
vector
<
double
>
&
out
);
void
fft
(
const
RVector
&
in
,
RVector
&
out
);
void
fft2
(
int
N2
,
int
N1
,
fftw_complex
*
in
,
fftw_complex
*
out
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment