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
cd6298fb
Commit
cd6298fb
authored
Nov 30, 2015
by
Manuel Günther
Browse files
Fixed Py3 issues with __repr__ functions
parent
68200670
Changes
7
Hide whitespace changes
Inline
Side-by-side
bob/core/random/binomial.cpp
View file @
cd6298fb
...
...
@@ -306,19 +306,7 @@ static PyMethodDef PyBoostBinomial_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
b
=
PyObject_Bytes
(
s
);
# else
PyObject
*
b
=
PyObject_Str
(
s
);
# endif
Py_DECREF
(
s
);
return
b
;
}
extern
PyObject
*
scalar_to_bytes
(
PyObject
*
s
);
/**
* String representation and print out
...
...
bob/core/random/discrete.cpp
View file @
cd6298fb
...
...
@@ -341,12 +341,6 @@ static PyMethodDef PyBoostDiscrete_methods[] = {
};
#if PY_VERSION_HEX >= 0x03000000
# define PYOBJECT_STR PyObject_Str
#else
# define PYOBJECT_STR PyObject_Unicode
#endif
/**
* String representation and print out
*/
...
...
@@ -355,26 +349,16 @@ static PyObject* PyBoostDiscrete_Repr(PyBoostDiscreteObject* self) {
PyObject
*
probabilities
=
PyBoostDiscrete_GetProbabilities
(
self
);
if
(
!
probabilities
)
return
0
;
auto
probabilities_
=
make_safe
(
probabilities
);
PyObject
*
prob_str
=
P
YOBJECT_STR
(
probabilities
);
PyObject
*
prob_str
=
P
yObject_Str
(
probabilities
);
if
(
!
prob_str
)
return
0
;
auto
prob_str_
=
make_safe
(
prob_str
);
PyObject
*
retval
=
PyUnicode
_FromFormat
(
return
PyString
_FromFormat
(
"%s(dtype='%s' , probabilities=%U)"
,
Py_TYPE
(
self
)
->
tp_name
,
PyBlitzArray_TypenumAsString
(
self
->
type_num
),
prob_str
);
#if PYTHON_VERSION_HEX < 0x03000000
if
(
!
retval
)
return
0
;
PyObject
*
tmp
=
PyObject_Str
(
retval
);
Py_DECREF
(
retval
);
retval
=
tmp
;
#endif
return
retval
;
}
PyTypeObject
PyBoostDiscrete_Type
=
{
...
...
bob/core/random/gamma.cpp
View file @
cd6298fb
...
...
@@ -264,19 +264,7 @@ static PyMethodDef PyBoostGamma_methods[] = {
{
0
}
/* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
b
=
PyObject_Bytes
(
s
);
# else
PyObject
*
b
=
PyObject_Str
(
s
);
# endif
Py_DECREF
(
s
);
return
b
;
}
extern
PyObject
*
scalar_to_bytes
(
PyObject
*
s
);
/**
* String representation and print out
...
...
bob/core/random/lognormal.cpp
View file @
cd6298fb
...
...
@@ -303,19 +303,7 @@ static PyMethodDef PyBoostLogNormal_methods[] = {
{
0
}
/* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
b
=
PyObject_Bytes
(
s
);
# else
PyObject
*
b
=
PyObject_Str
(
s
);
# endif
Py_DECREF
(
s
);
return
b
;
}
extern
PyObject
*
scalar_to_bytes
(
PyObject
*
s
);
/**
* String representation and print out
...
...
bob/core/random/main.cpp
View file @
cd6298fb
...
...
@@ -18,6 +18,18 @@ static PyMethodDef module_methods[] = {
{
0
}
/* Sentinel */
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
* This function will be used in the bindings of all Boost classes
*/
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
auto
s_
=
make_safe
(
s
);
PyObject
*
b
=
PyObject_Str
(
s
);
return
b
;
}
PyDoc_STRVAR
(
module_docstr
,
"boost::random classes and methods"
);
...
...
bob/core/random/normal.cpp
View file @
cd6298fb
...
...
@@ -301,19 +301,7 @@ static PyMethodDef PyBoostNormal_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
b
=
PyObject_Bytes
(
s
);
# else
PyObject
*
b
=
PyObject_Str
(
s
);
# endif
Py_DECREF
(
s
);
return
b
;
}
extern
PyObject
*
scalar_to_bytes
(
PyObject
*
s
);
/**
* String representation and print out
...
...
bob/core/random/uniform.cpp
View file @
cd6298fb
...
...
@@ -492,20 +492,8 @@ static PyMethodDef PyBoostUniform_methods[] = {
};
/**
* Converts a scalar, that will be stolen, into a str/bytes
*/
static
PyObject
*
scalar_to_bytes
(
PyObject
*
s
)
{
if
(
!
s
)
return
s
;
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
b
=
PyObject_Bytes
(
s
);
# else
PyObject
*
b
=
PyObject_Str
(
s
);
# endif
Py_DECREF
(
s
);
return
b
;
}
extern
PyObject
*
scalar_to_bytes
(
PyObject
*
s
);
/**
* String representation and print 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