PyErr_SetString(PyExc_TypeError,"Activation function only supports 64-bit float arrays for input array `z'");
return0;
}
if(res->type_num!=NPY_FLOAT64){
PyErr_SetString(PyExc_TypeError,"Activation function only supports 64-bit float arrays for output array `res'");
return0;
}
if(z->ndim<1||z->ndim>4){
PyErr_Format(PyExc_TypeError,"Activation function only accepts 1, 2, 3 or 4-dimensional arrays (not %"PY_FORMAT_SIZE_T"dD arrays)",z->ndim);
return0;
}
if(z->ndim!=res->ndim){
PyErr_Format(PyExc_RuntimeError,"Input and output arrays should have matching number of dimensions, but input array `z' has %"PY_FORMAT_SIZE_T"d dimensions while output array `res' has %"PY_FORMAT_SIZE_T"d dimensions",z->ndim,res->ndim);
return0;
}
for(Py_ssize_ti=0;i<z->ndim;++i){
if(z->shape[i]!=res->shape[i]){
PyErr_Format(PyExc_RuntimeError,"Input and output arrays should have matching sizes, but dimension %"PY_FORMAT_SIZE_T"d of input array `z' has %"PY_FORMAT_SIZE_T"d positions while output array `res' has %"PY_FORMAT_SIZE_T"d positions",z->shape[i],res->shape[i]);
return0;
}
}
//at this point all checks are done, we can proceed into calling C++
PyErr_Format(PyExc_RuntimeError,"number of arguments mismatch - %s requires 1 or 2 arguments, but you provided %"PY_FORMAT_SIZE_T"d (see help)",s_call_str,nargs);
.def("__call__", &activation_f_ndarray_1, (arg("self"), arg("z"), arg("res")), "Computes the activated value, given an input array ``z``, placing results in ``res`` (and returning it)")
.def("__call__", &activation_f_ndarray_2, (arg("self"), arg("z")), "Computes the activated value, given an input array ``z``. Returns a newly allocated array with the same size as ``z``")
.def("__call__", &bob::machine::Activation::f, (arg("self"), arg("z")), "Computes the activated value, given an input ``z``")
.def("f_prime", &activation_f_prime_ndarray_1, (arg("self"), arg("z"), arg("res")), "Computes the derivative of the activated value, placing results in ``res`` (and returning it)")
.def("f_prime", &activation_f_prime_ndarray_2, (arg("self"), arg("z")), "Computes the derivative of the activated value, given an input array ``z``. Returns a newly allocated array with the same size as ``z``")
.def("f_prime", &bob::machine::Activation::f_prime, (arg("self"), arg("z")), "Computes the derivative of the activated value.")
.def("f_prime_from_f", &activation_f_prime_from_f_ndarray_1, (arg("self"), arg("a"), arg("res")), "Computes the derivative of the activated value, given **the activated value** ``a``, placing results in ``res`` (and returning it)")
.def("f_prime_from_f", &activation_f_prime_from_f_ndarray_2, (arg("self"), arg("z")), "Computes the derivative of the activated value, given **the activated value** ``a``. Returns a newly allocated array with the same size as ``a`` with the answer.")
.def("f_prime_from_f", &bob::machine::Activation::f_prime_from_f, (arg("self"), arg("a")), "Computes the derivative of the activation value, given **the activated value** ``a``.")