Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.core
Commits
c06156bd
Commit
c06156bd
authored
Oct 24, 2014
by
Manuel Günther
Browse files
Next trial to remove erros on Travis.
parent
c42e7e33
Changes
3
Hide whitespace changes
Inline
Side-by-side
bob/core/include/bob.core/random.h
View file @
c06156bd
...
...
@@ -10,27 +10,6 @@
#include <boost/random.hpp>
namespace
bob
{
namespace
core
{
namespace
random
{
// for completeness, we provide the interfaces for other distributions through bob::core::random
template
<
class
UniformRandomNumberGenerator
=
double
,
class
RealType
=
double
>
using
uniform_01
=
boost
::
uniform_01
<
UniformRandomNumberGenerator
,
RealType
>
;
template
<
class
IntType
=
int
>
using
uniform_smallint_distribution
=
boost
::
uniform_smallint
<
IntType
>
;
template
<
class
IntType
=
int
>
using
uniform_int_distribution
=
boost
::
uniform_int
<
IntType
>
;
template
<
class
RealType
=
double
>
using
uniform_real_distribution
=
boost
::
uniform_real
<
RealType
>
;
template
<
class
RealType
=
double
>
using
gamma_distribution
=
boost
::
gamma_distribution
<
RealType
>
;
}
}
}
#include <boost/version.hpp>
#if BOOST_VERSION >= 105600
...
...
bob/core/random/gamma.cpp
View file @
c06156bd
...
...
@@ -10,6 +10,7 @@
#include <bob.blitz/cppapi.h>
#include <boost/make_shared.hpp>
#include <boost/random.hpp>
#include <bob.core/random.h>
PyDoc_STRVAR
(
s_gamma_str
,
BOB_EXT_MODULE_PREFIX
".gamma"
);
...
...
@@ -52,7 +53,7 @@ template <typename T>
boost
::
shared_ptr
<
void
>
make_gamma
(
PyObject
*
alpha
)
{
T
calpha
=
1.
;
if
(
alpha
)
calpha
=
PyBlitzArrayCxx_AsCScalar
<
T
>
(
alpha
);
return
boost
::
make_shared
<
bo
b
::
core
::
random
::
gamma_distribution
<
T
>>
(
calpha
);
return
boost
::
make_shared
<
bo
ost
::
gamma_distribution
<
T
>>
(
calpha
);
}
PyObject
*
PyBoostGamma_SimpleNew
(
int
type_num
,
PyObject
*
alpha
)
{
...
...
@@ -129,7 +130,7 @@ int PyBoostGamma_Converter(PyObject* o, PyBoostGammaObject** a) {
}
template
<
typename
T
>
PyObject
*
get_alpha
(
PyBoostGammaObject
*
self
)
{
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
b
::
core
::
random
::
gamma_distribution
<
T
>>
(
self
->
distro
)
->
alpha
());
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
ost
::
gamma_distribution
<
T
>>
(
self
->
distro
)
->
alpha
());
}
/**
...
...
@@ -155,7 +156,7 @@ static PyObject* PyBoostGamma_GetDtype(PyBoostGammaObject* self) {
}
template
<
typename
T
>
PyObject
*
reset
(
PyBoostGammaObject
*
self
)
{
boost
::
static_pointer_cast
<
bo
b
::
core
::
random
::
gamma_distribution
<
T
>>
(
self
->
distro
)
->
reset
();
boost
::
static_pointer_cast
<
bo
ost
::
gamma_distribution
<
T
>>
(
self
->
distro
)
->
reset
();
Py_RETURN_NONE
;
}
...
...
@@ -176,7 +177,7 @@ static PyObject* PyBoostGamma_Reset(PyBoostGammaObject* self) {
}
template
<
typename
T
>
PyObject
*
call
(
PyBoostGammaObject
*
self
,
PyBoostMt19937Object
*
rng
)
{
typedef
bo
b
::
core
::
random
::
gamma_distribution
<
T
>
distro_t
;
typedef
bo
ost
::
gamma_distribution
<
T
>
distro_t
;
return
PyBlitzArrayCxx_FromCScalar
((
*
boost
::
static_pointer_cast
<
distro_t
>
(
self
->
distro
))(
*
rng
->
rng
));
}
...
...
bob/core/random/uniform.cpp
View file @
c06156bd
...
...
@@ -10,7 +10,7 @@
#include <bob.blitz/cppapi.h>
#include <boost/make_shared.hpp>
#include <bo
b.core
/random.h>
#include <bo
ost
/random.h
pp
>
PyDoc_STRVAR
(
s_uniform_str
,
BOB_EXT_MODULE_PREFIX
".uniform"
);
...
...
@@ -34,7 +34,7 @@ static void PyBoostUniform_Delete (PyBoostUniformObject* o) {
}
static
boost
::
shared_ptr
<
void
>
make_uniform_bool
()
{
return
boost
::
make_shared
<
bo
b
::
core
::
random
::
uniform_smallint
_distribution
<
uint8_t
>>
(
0
,
1
);
return
boost
::
make_shared
<
bo
ost
::
uniform_smallint
<
uint8_t
>>
(
0
,
1
);
}
template
<
typename
T
>
...
...
@@ -43,7 +43,7 @@ boost::shared_ptr<void> make_uniform_int(PyObject* min, PyObject* max) {
if
(
min
)
cmin
=
PyBlitzArrayCxx_AsCScalar
<
T
>
(
min
);
T
cmax
=
9
;
if
(
max
)
cmax
=
PyBlitzArrayCxx_AsCScalar
<
T
>
(
max
);
return
boost
::
make_shared
<
bo
b
::
core
::
random
::
uniform_int_distribution
<
T
>>
(
cmin
,
cmax
);
return
boost
::
make_shared
<
bo
ost
::
uniform_int
<
T
>>
(
cmin
,
cmax
);
}
template
<
typename
T
>
...
...
@@ -52,7 +52,7 @@ boost::shared_ptr<void> make_uniform_real(PyObject* min, PyObject* max) {
if
(
min
)
cmin
=
PyBlitzArrayCxx_AsCScalar
<
T
>
(
min
);
T
cmax
=
1
;
if
(
max
)
cmax
=
PyBlitzArrayCxx_AsCScalar
<
T
>
(
max
);
return
boost
::
make_shared
<
bo
b
::
core
::
random
::
uniform_real
_distribution
<
T
>>
(
cmin
,
cmax
);
return
boost
::
make_shared
<
bo
ost
::
uniform_real
<
T
>>
(
cmin
,
cmax
);
}
PyObject
*
PyBoostUniform_SimpleNew
(
int
type_num
,
PyObject
*
min
,
PyObject
*
max
)
{
...
...
@@ -332,16 +332,16 @@ static PyObject* PyBoostUniform_Reset(PyBoostUniformObject* self) {
}
static
PyObject
*
call_bool
(
PyBoostUniformObject
*
self
,
PyBoostMt19937Object
*
rng
)
{
if
(
boost
::
static_pointer_cast
<
bo
b
::
core
::
random
::
uniform_smallint
_distribution
<
uint8_t
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
))
Py_RETURN_TRUE
;
if
(
boost
::
static_pointer_cast
<
bo
ost
::
uniform_smallint
<
uint8_t
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
))
Py_RETURN_TRUE
;
Py_RETURN_FALSE
;
}
template
<
typename
T
>
PyObject
*
call_int
(
PyBoostUniformObject
*
self
,
PyBoostMt19937Object
*
rng
)
{
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
b
::
core
::
random
::
uniform_int_distribution
<
T
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
));
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
ost
::
uniform_int
<
T
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
));
}
template
<
typename
T
>
PyObject
*
call_real
(
PyBoostUniformObject
*
self
,
PyBoostMt19937Object
*
rng
)
{
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
b
::
core
::
random
::
uniform_real
_distribution
<
T
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
));
return
PyBlitzArrayCxx_FromCScalar
(
boost
::
static_pointer_cast
<
bo
ost
::
uniform_real
<
T
>>
(
self
->
distro
)
->
operator
()(
*
rng
->
rng
));
}
/**
...
...
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