C++ API¶
The C++ API of bob.learn.activation
allows users to leverage from
automatic converters for classes in bob.learn.activation
. To use
the C API, clients should first, include the header file
<bob.learn.activation/api.h>
on their compilation units and then, make
sure to call once import_bob_learn_activation()
at their module
instantiation, as explained at the Python manual.
Here is a dummy C example showing how to include the header and where to call the import function:
#include <bob.learn.activation/api.h>
PyMODINIT_FUNC initclient(void) {
PyObject* m Py_InitModule("client", ClientMethods);
if (!m) return;
// imports dependencies
if (import_bob_blitz() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import module");
return 0;
}
if (import_bob_io_base() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import module");
return 0;
}
if (import_bob_learn_activation() < 0) {
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "cannot import module");
return 0;
}
// imports bob.learn.activation C-API
import_bob_learn_activation();
}
Activation Functors¶
-
type
PyBobLearnActivationObject
¶ The pythonic object representation for a
bob::machine::Activation
object. It is the base class of all activation functors available in Bob. In C/C++ code, we recommend you only manipulate objects like this to keep your code agnostic to the activation type being used.typedef struct { PyObject_HEAD bob::machine::Activation* base; } PyBobLearnActivationObject;
-
bob::machine::Activation *
base
¶ A pointer to the activation functor virtual implementation.
-
bob::machine::Activation *
-
int
PyBobLearnActivation_Check
(PyObject *o)¶ Checks if the input object
o
is aPyBobLearnActivationObject
. Returns1
if it is, and0
otherwise.
Constructs a new
PyBobLearnActivationObject
starting from a shared pointer to a pre-allocated bob::machine::Activation instance. This API is available so that return values from actuall C++ machines can be mapped into Python. It is the sole way to build an object of typeActivation
without recurring to the derived classes.
Note
Other object definitions exist for each of the specializations for activation functors found in Bob. They are exported through the module C-API, but we don’t recommend using them since you’d loose generality. In case you do absolutely need to use any of these derivations, they have all the same object configuration:
typedef struct {
PyBobLearnActivationObject parent;
bob::machine::<Subtype>Activation* base;
} PyBobLearn<Subtype>ActivationObject;
Presently, <Subtype>
can be one of:
- Identity
- Linear
- Logistic
- HyperbolicTangent
- MultipliedHyperbolicTangent
Type objects are also named consistently like
PyBobLearn<Subtype>Activation_Type
.