Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Seitosh
Seitosh
Commits
58bb24b1
Commit
58bb24b1
authored
Mar 19, 2016
by
thomas.forbriger
Browse files
Merge branch 'master' into stf_issue12
parents
dd25ad1d
699c7722
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/libs/libtsxx/random.cc
View file @
58bb24b1
...
...
@@ -4,11 +4,11 @@
* ----------------------------------------------------------------------------
*
* \author Thomas Forbriger
* \date
27
/0
6
/20
0
6
* \date
19
/0
3
/20
1
6
*
* create a random series (implementation)
*
* Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
* Copyright (c) 2006
, 2016
by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
...
...
@@ -29,11 +29,12 @@
*
* REVISIONS and CHANGES
* - 27/06/2006 V1.0 Thomas Forbriger
* - 19/03/2016 V1.1 seed sequence only once
*
* ============================================================================
*/
#define TS_RANDOM_CC_VERSION \
"TS_RANDOM_CC V1.
0
"
"TS_RANDOM_CC V1.
1
"
#include <tsxx/random.h>
#include <gsl/gsl_rng.h>
...
...
@@ -44,20 +45,39 @@ namespace ts {
namespace
rnd
{
namespace
helper
{
//! internal class used for static variable in dugauss
class
GSLrng
{
public:
explicit
GSLrng
(
const
gsl_rng_type
*
T
)
{
gsl_rng_env_setup
();
MR
=
gsl_rng_alloc
(
T
);
this
->
seed
();
}
~
GSLrng
()
{
gsl_rng_free
(
MR
);
}
double
ugaussian
()
const
{
return
gsl_ran_ugaussian
(
MR
);
}
void
seed
(
const
unsigned
long
int
&
seedvalue
)
const
{
gsl_rng_set
(
MR
,
seedvalue
);
}
void
seed
()
const
{
this
->
seed
(
time
(
0
));
}
private:
gsl_rng
*
MR
;
};
// class GSLrng
}
// namespace helper
/* ---------------------------------------------------------------------- */
Tdseries
dugauss
(
const
int
&
n
)
{
static
helper
::
GSLrng
rng
(
gsl_rng_default
);
Tdseries
retval
(
n
);
gsl_rng_env_setup
();
const
gsl_rng_type
*
T
=
gsl_rng_default
;
gsl_rng
*
R
=
gsl_rng_alloc
(
T
);
gsl_rng_set
(
R
,
time
(
0
));
for
(
int
i
=
retval
.
f
();
i
<=
retval
.
l
();
++
i
)
{
retval
(
i
)
=
gsl_ran_ugaussian
(
R
);
}
gsl_rng_free
(
R
);
{
retval
(
i
)
=
rng
.
ugaussian
();
}
return
(
retval
);
}
// Tdseries dugauss
}
// namespace rnd
}
// namespace ts
...
...
src/libs/libtsxx/tstest.cc
View file @
58bb24b1
...
...
@@ -4,7 +4,7 @@
* ----------------------------------------------------------------------------
*
* \author Thomas Forbriger
* \date
20/12/2003
* \date
19/03/2016
*
* test time series modules
*
...
...
@@ -33,11 +33,12 @@
* - 21/11/2006 V1.2 test drop containers
* - 28/01/2012 V1.3 test OffsetVariableTaper
* - 20/05/2015 V1.4 print library usage texts
* - 19/03/2016 V1.5 test subsequent calls to function dugauss
*
* ============================================================================
*/
#define TSTEST_VERSION \
"TSTEST V1.
4
test time series modules"
"TSTEST V1.
5
test time series modules"
#include <tfxx/commandline.h>
#include <iostream>
...
...
@@ -182,7 +183,9 @@ int main(int iargc, char* argv[])
if
(
opt
.
randomnoise
)
{
cout
<<
"test random noise generation"
<<
endl
;
ts
::
rnd
::
Tdseries
s
=
ts
::
rnd
::
dugauss
(
30
);
ts
::
rnd
::
Tdseries
s
=
ts
::
rnd
::
dugauss
(
10
);
DUMP
(
s
);
s
=
ts
::
rnd
::
dugauss
(
10
);
DUMP
(
s
);
}
...
...
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