Commit fe06cddc authored by Manuel Günther's avatar Manuel Günther

Removed the fucntion_ and function_nocheck implementations that are use nowhere esle

parent 72ffb6c2
Pipeline #10429 passed with stages
in 7 minutes and 41 seconds
......@@ -15,11 +15,7 @@
double bob::math::det(const blitz::Array<double,2>& A)
{
bob::core::array::assertSameDimensionLength(A.extent(0),A.extent(1));
return bob::math::det_(A);
}
double bob::math::det_(const blitz::Array<double,2>& A)
{
// Size variable
int N = A.extent(0);
......@@ -53,11 +49,7 @@ double bob::math::det_(const blitz::Array<double,2>& A)
double bob::math::slogdet(const blitz::Array<double,2>& A, int& sign)
{
bob::core::array::assertSameDimensionLength(A.extent(0),A.extent(1));
return bob::math::slogdet_(A, sign);
}
double bob::math::slogdet_(const blitz::Array<double,2>& A, int& sign)
{
// Size variable
int N = A.extent(0);
......@@ -91,4 +83,3 @@ double bob::math::slogdet_(const blitz::Array<double,2>& A, int& sign)
return Udiag;
}
......@@ -35,14 +35,6 @@ void bob::math::inv(const blitz::Array<double,2>& A, blitz::Array<double,2>& B)
bob::core::array::assertSameShape(A,shapeA);
bob::core::array::assertSameShape(B,shapeA);
bob::math::inv_(A, B);
}
void bob::math::inv_(const blitz::Array<double,2>& A, blitz::Array<double,2>& B)
{
// Size variable
const int N = A.extent(0);
//////////////////////////////////////
// Prepares to call LAPACK functions
// Initializes LAPACK variables
......@@ -96,4 +88,3 @@ void bob::math::inv_(const blitz::Array<double,2>& A, blitz::Array<double,2>& B)
if (!B_direct_use)
B = A_blitz_lapack;
}
......@@ -45,17 +45,6 @@ void bob::math::lu(const blitz::Array<double,2>& A, blitz::Array<double,2>& L,
bob::core::array::assertSameShape(U,shapeU);
bob::core::array::assertSameShape(P,shapeP);
bob::math::lu_(A, L, U, P);
}
void bob::math::lu_(const blitz::Array<double,2>& A, blitz::Array<double,2>& L,
blitz::Array<double,2>& U, blitz::Array<double,2>& P)
{
// Size variable
const int M = A.extent(0);
const int N = A.extent(1);
const int minMN = std::min(M,N);
// Prepares to call LAPACK function
// Initialises LAPACK variables
......@@ -116,15 +105,6 @@ void bob::math::chol(const blitz::Array<double,2>& A,
bob::core::array::assertSameDimensionLength(M,N);
bob::core::array::assertSameShape(A,L);
bob::math::chol_(A, L);
}
void bob::math::chol_(const blitz::Array<double,2>& A,
blitz::Array<double,2>& L)
{
// Size variable
const int N = A.extent(0);
// Prepares to call LAPACK function
// Initialises LAPACK variables
int info = 0;
......@@ -161,4 +141,3 @@ void bob::math::chol_(const blitz::Array<double,2>& A,
blitz::secondIndex j;
L = blitz::where(i < j, 0, L);
}
......@@ -11,13 +11,6 @@
#include <bob.core/assert.h>
void bob::math::pavx(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat)
{
bob::core::array::assertSameShape(y, ghat);
assert(y.extent(0) > 0);
math::pavx_(y, ghat);
}
static size_t pavx_1(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat,
blitz::Array<size_t,1>& index, blitz::Array<size_t,1>& len)
{
......@@ -64,8 +57,11 @@ static void pavx_2(blitz::Array<double,1>& ghat, blitz::Array<size_t,1>& index,
}
}
void bob::math::pavx_(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat)
void bob::math::pavx(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat)
{
bob::core::array::assertSameShape(y, ghat);
assert(y.extent(0) > 0);
// Define working arrays: An interval of indices is represented by its left
// endpoint "index" and its length "len"
int N = y.extent(0);
......
......@@ -28,15 +28,6 @@ void bob::math::sqrtSymReal(const blitz::Array<double,2>& A,
bob::core::array::assertSameShape(A,shape);
bob::core::array::assertSameShape(B,shape);
bob::math::sqrtSymReal_(A, B);
}
void bob::math::sqrtSymReal_(const blitz::Array<double,2>& A,
blitz::Array<double,2>& B)
{
// Size variable
int N = A.extent(0);
// 1/ Perform the Eigenvalue decomposition of the symmetric matrix
// A = V.D.V^T, and V^-1=V^T
blitz::Array<double,2> V(N,N);
......
......@@ -20,12 +20,6 @@ namespace bob { namespace math {
* @param A The A matrix to consider (size NxN)
*/
double det(const blitz::Array<double,2>& A);
/**
* @brief Function which computes the determinant of a square matrix
* @param A The A matrix to consider (size NxN)
* @warning Does not check the input matrix
*/
double det_(const blitz::Array<double,2>& A);
/**
* @brief Function which computes the sign and (natural) logarithm of
......@@ -35,15 +29,6 @@ namespace bob { namespace math {
* (-1 if negative, 0 if zero, +1 if positive)
*/
double slogdet(const blitz::Array<double,2>& A, int& sign);
/**
* @brief Function which computes the sign and (natural) logarithm of
* the determinant of a square matrix
* @param A The A matrix to consider (size NxN)
* @param sign The (output) sign of the determinant
* (-1 if negative, 0 if zero, +1 if positive)
* @warning Does not check the input matrix
*/
double slogdet_(const blitz::Array<double,2>& A, int& sign);
}}
......
......@@ -25,12 +25,14 @@ namespace bob { namespace math {
* @param input The input blitz array
* @param g The output blitz array for the gradient
* @param dx The sample distance along the x-axis
* @warning Does not check that g has the same size as input
*/
template <typename T, typename U>
void gradient_(const blitz::Array<T,1>& input, blitz::Array<U,1>& g,
void gradient(const blitz::Array<T,1>& input, blitz::Array<U,1>& g,
const double dx=1.)
{
// Check input size
bob::core::array::assertSameShape(input, g);
const int M=input.extent(0);
// Check input
if (M<2) {
......@@ -64,24 +66,6 @@ namespace bob { namespace math {
if (dx!=1.) g *= (1./dx);
}
/**
* @brief Function which computes the gradient of a 1D signal
* The gradient is computed using central differences in the interior
* and first differences at the boundaries.
* Similar to NumPy and MATLAB gradient function
* @param input The input blitz array
* @param dx The sample distance along the x-axis
* @param g The output blitz array for the gradient
*/
template <typename T, typename U>
void gradient(const blitz::Array<T,1>& input, blitz::Array<U,1>& g,
const double dx=1.)
{
// Check input size
bob::core::array::assertSameShape(input, g);
gradient_<T,U>(input, g, dx);
}
/**
* @brief Function which computes the gradient of a 2D signal
* The gradient is computed using central differences in the interior
......@@ -92,13 +76,15 @@ namespace bob { namespace math {
* @param gx The output blitz array for the gradient along the x-axis
* @param dy The sample distance along the y-axis
* @param dx The sample distance along the x-axis
* @warning Does not check that gx and gy have the same size as input
* @warning For unsigned input datatypes, this function might not work as expected.
*/
template <typename T, typename U>
void gradient_(const blitz::Array<T,2>& input, blitz::Array<U,2>& gy,
void gradient(const blitz::Array<T,2>& input, blitz::Array<U,2>& gy,
blitz::Array<U,2>& gx, const double dy=1., const double dx=1.)
{
bob::core::array::assertSameShape(input, gy);
bob::core::array::assertSameShape(input, gx);
const int M=input.extent(0);
const int N=input.extent(1);
// Check input
......@@ -157,27 +143,6 @@ namespace bob { namespace math {
if (dy!=1.) gy *= (1./dy);
if (dx!=1.) gx *= (1./dx);
}
/**
* @brief Function which computes the gradient of a 2D signal
* The gradient is computed using central differences in the interior
* and first differences at the boundaries.
* Similar to NumPy and MATLAB gradient function
* @param input The input blitz array
* @param gy The output blitz array for the gradient along the y-axis
* @param gx The output blitz array for the gradient along the x-axis
* @param dy The sample distance along the y-axis
* @param dx The sample distance along the x-axis
* @warning For unsigned input datatypes, this function might not work as expected.
*/
template <typename T, typename U>
void gradient(const blitz::Array<T,2>& input, blitz::Array<U,2>& gy,
blitz::Array<U,2>& gx, const double dy=1., const double dx=1.)
{
// Check input size
bob::core::array::assertSameShape(input, gy);
bob::core::array::assertSameShape(input, gx);
gradient_<T,U>(input, gy, gx, dy, dx);
}
/**
* @brief Function which computes the gradient of a 3D signal
......@@ -191,14 +156,17 @@ namespace bob { namespace math {
* @param dz The sample distance along the z-axis
* @param dy The sample distance along the y-axis
* @param dx The sample distance along the x-axis
* @warning Does not check that gx and gy have the same size as input
* @warning For unsigned input datatypes, this function might not work as expected.
*/
template <typename T, typename U>
void gradient_(const blitz::Array<T,3>& input, blitz::Array<U,3>& gz,
void gradient(const blitz::Array<T,3>& input, blitz::Array<U,3>& gz,
blitz::Array<U,3>& gy, blitz::Array<U,3>& gx, const double dz=1.,
const double dy=1., const double dx=1.)
{
bob::core::array::assertSameShape(input, gz);
bob::core::array::assertSameShape(input, gy);
bob::core::array::assertSameShape(input, gx);
const int M=input.extent(0);
const int N=input.extent(1);
const int P=input.extent(2);
......@@ -280,32 +248,6 @@ namespace bob { namespace math {
if (dy!=1.) gy *= (1./dy);
if (dx!=1.) gx *= (1./dx);
}
/**
* @brief Function which computes the gradient of a 3D signal
* The gradient is computed using central differences in the interior
* and first differences at the boundaries.
* Similar to NumPy and MATLAB gradient function
* @param input The input blitz array
* @param gz The output blitz array for the gradient along the z-axis
* @param gy The output blitz array for the gradient along the y-axis
* @param gx The output blitz array for the gradient along the x-axis
* @param dz The sample distance along the z-axis
* @param dy The sample distance along the y-axis
* @param dx The sample distance along the x-axis
* @warning For unsigned input datatypes, this function might not work as expected.
*/
template <typename T, typename U>
void gradient(const blitz::Array<T,3>& input, blitz::Array<U,3>& gz,
blitz::Array<U,3>& gy, blitz::Array<U,3>& gx, const double dz=1.,
const double dy=1., const double dx=1.)
{
// Check input size
bob::core::array::assertSameShape(input, gz);
bob::core::array::assertSameShape(input, gy);
bob::core::array::assertSameShape(input, gx);
gradient_<T,U>(input, gz, gy, gx, dz, dy, dx);
}
}}
#endif /* BOB_MATH_GRADIENT_H */
......@@ -21,7 +21,6 @@ namespace bob { namespace math {
* @param B The B=inverse(A) matrix (size NxN)
*/
void inv(const blitz::Array<double,2>& A, blitz::Array<double,2>& B);
void inv_(const blitz::Array<double,2>& A, blitz::Array<double,2>& B);
}}
......
......@@ -22,8 +22,6 @@ namespace bob { namespace math {
*/
void lu(const blitz::Array<double,2>& A, blitz::Array<double,2>& L,
blitz::Array<double,2>& U, blitz::Array<double,2>& P);
void lu_(const blitz::Array<double,2>& A, blitz::Array<double,2>& L,
blitz::Array<double,2>& U, blitz::Array<double,2>& P);
/**
* @brief Performs the Cholesky decomposition of a real symmetric
......@@ -35,7 +33,6 @@ namespace bob { namespace math {
* @param L The L lower-triangular matrix of the decomposition
*/
void chol(const blitz::Array<double,2>& A, blitz::Array<double,2>& L);
void chol_(const blitz::Array<double,2>& A, blitz::Array<double,2>& L);
/**
* @}
*/
......
......@@ -33,7 +33,6 @@ namespace bob { namespace math {
* Duembgen is that the data points of the vector y can not be weighted.
*/
void pavx(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat);
void pavx_(const blitz::Array<double,1>& y, blitz::Array<double,1>& ghat);
/**
* This variant additionally returns the width vector of the pav bins,
......
......@@ -20,14 +20,13 @@ namespace bob { namespace math {
*/
/**
* @brief Function which computes the (unique) square root of a real
* @brief Function which computes the (unique) square root of a real
* symmetric definite-positive matrix.
* @warning The input matrix should be symmetric.
* @param A The A matrix to decompose (size NxN)
* @param B The square root matrix B of A (size NxN)
*/
void sqrtSymReal(const blitz::Array<double,2>& A, blitz::Array<double,2>& B);
void sqrtSymReal_(const blitz::Array<double,2>& A, blitz::Array<double,2>& B);
void sqrtSymReal(const blitz::Array<double,2>& A, blitz::Array<double,2>& B);
/**
* @}
......
......@@ -99,24 +99,6 @@ static bob::extension::FunctionDoc s_pavx = bob::extension::FunctionDoc(
.add_return("output", "array_like (float, 1D)", "The output matrix; will be created in the same size as ``input``")
;
static bob::extension::FunctionDoc s_pavx_nocheck = bob::extension::FunctionDoc(
"pavx_",
"Applies the Pool-Adjacent-Violators Algorithm",
".. warning:: This variant does not perform any checks on the input matrices and is faster then :py:func:`pavx`. "
"Use it when you are sure your input matrices sizes match.\n\n"
"Applies the Pool-Adjacent-Violators Algorithm to ``input``. "
"This is a simplified C++ port of the isotonic regression code made available at the `University of Bern website <http://www.imsv.unibe.ch/content/staff/personalhomepages/duembgen/software/isotonicregression/index_eng.html>`_.\n\n"
"You can use this method in two different formats. "
"The first interface accepts the ``input`` and ``output``. "
"The second one accepts the input array ``input`` and allocates a new ``output`` array, which is returned. "
)
.add_prototype("input, output")
.add_prototype("input", "output")
.add_parameter("input", "array_like (float, 1D)", "The input matrix for the PAV algorithm.")
.add_parameter("output", "array_like (float, 1D)", "The output matrix, must be of the same size as ``input``")
.add_return("output", "array_like (float, 1D)", "The output matrix; will be created in the same size as ``input``")
;
static bob::extension::FunctionDoc s_pavx_width = bob::extension::FunctionDoc(
"pavxWidth",
"Applies the Pool-Adjacent-Violators Algorithm and returns the width.",
......@@ -334,12 +316,6 @@ static PyMethodDef module_methods[] = {
METH_VARARGS|METH_KEYWORDS,
s_pavx.doc()
},
{
s_pavx_nocheck.name(),
(PyCFunction)py_pavx_nocheck,
METH_VARARGS|METH_KEYWORDS,
s_pavx_nocheck.doc()
},
{
s_pavx_width.name(),
(PyCFunction)py_pavx_width,
......
......@@ -72,53 +72,6 @@ PyObject* py_pavx (PyObject*, PyObject* args, PyObject* kwds) {
}
PyObject* py_pavx_nocheck (PyObject*, PyObject* args, PyObject* kwds) {
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "input", "output", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
PyBlitzArrayObject* input = 0;
PyBlitzArrayObject* output = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&",
kwlist,
&PyBlitzArray_Converter, &input,
&PyBlitzArray_OutputConverter, &output
)) return 0;
//protects acquired resources through this scope
auto input_ = make_safe(input);
auto output_ = make_safe(output);
// can only handle 1D arrays
if (input->ndim != 1 || output->ndim != 1) {
PyErr_SetString(PyExc_TypeError, "input and output arrays should be one-dimensional");
return 0;
}
// can only handle float arrays
if (input->type_num != NPY_FLOAT64 || output->type_num != NPY_FLOAT64) {
PyErr_SetString(PyExc_TypeError, "input and output arrays data types should be float (i.e. `numpy.float64' equivalents)");
return 0;
}
try {
bob::math::pavx_(*PyBlitzArrayCxx_AsBlitz<double,1>(input),
*PyBlitzArrayCxx_AsBlitz<double,1>(output));
}
catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
catch (...) {
PyErr_SetString(PyExc_RuntimeError, "pavx failed: unknown exception caught");
return 0;
}
Py_RETURN_NONE;
}
PyObject* py_pavx_width (PyObject*, PyObject* args, PyObject* kwds) {
/* Parses input arguments in a single shot */
......
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 4 Dec 17:46:18 2013
* @date Wed 4 Dec 17:46:18 2013
*
* @brief Declaration of components relevant for main.cpp
*/
......@@ -8,6 +8,5 @@
#include <Python.h>
PyObject* py_pavx(PyObject*, PyObject* args, PyObject* kwds);
PyObject* py_pavx_nocheck(PyObject*, PyObject* args, PyObject* kwds);
PyObject* py_pavx_width(PyObject*, PyObject* args, PyObject* kwds);
PyObject* py_pavx_width_height(PyObject*, PyObject* args, PyObject* kwds);
......@@ -9,7 +9,7 @@
"""
import os, sys
from bob.math import pavx, pavx_, pavxWidth, pavxWidthHeight
from bob.math import pavx, pavxWidth, pavxWidthHeight
import numpy
def pavx_check(y, ghat_ref, w_ref, h_ref):
......@@ -17,7 +17,7 @@ def pavx_check(y, ghat_ref, w_ref, h_ref):
ghat = pavx(y)
assert numpy.all(numpy.abs(ghat - ghat_ref) < 1e-4)
pavx_(y, ghat)
pavx(y, ghat)
assert numpy.all(numpy.abs(ghat - ghat_ref) < 1e-4)
w=pavxWidth(y, ghat)
assert numpy.all(numpy.abs(w - w_ref) < 1e-4)
......@@ -31,7 +31,7 @@ def test_pavx_sample1():
# Reference obtained using bosaris toolkit 1.06
y = numpy.array([ 58.4666, 67.1040, 73.1806, 77.0896, 85.8816,
89.6381, 101.6651, 102.5587, 109.7933, 117.5715,
89.6381, 101.6651, 102.5587, 109.7933, 117.5715,
118.1671, 138.3151, 141.9755, 145.7352, 159.1108,
156.8654, 168.6932, 175.2756])
ghat_ref = numpy.array([ 58.4666, 67.1040, 73.1806, 77.0896, 85.8816,
......@@ -58,7 +58,7 @@ def test_pavx_sample2():
132.1742, 140.2783, 140.2783, 150.7383, 150.7383,
150.7383, 154.7762, 180.8819])
w_ref = numpy.array([1, 1, 1, 1, 3, 1, 1, 2, 2, 3, 1, 1])
h_ref = numpy.array([ 46.1093, 64.3255, 76.5252, 89.0061, 92.4618,
h_ref = numpy.array([ 46.1093, 64.3255, 76.5252, 89.0061, 92.4618,
98.5769, 102.3841, 132.1742, 140.2783, 150.7383,
154.7762, 180.8819])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment