Commit a9a32369 authored by André Anjos's avatar André Anjos 💬

Merge branch '1-bob-math-linsolve-parameter-documentation-in-inconsistent-order' into 'master'

Resolve "bob.math.linsolve parameter documentation in inconsistent order"

Closes #1

See merge request !13
parents 50d5c18e b326caef
Pipeline #10483 passed with stages
in 12 minutes and 30 seconds
......@@ -252,7 +252,7 @@ void bob::math::LPInteriorPoint::centeringV(const blitz::Array<double,2>& A,
// 2) Update the big system and solve it
updateLargeSystem( x, 1., m);
bob::math::linsolve( m_cache_A_large, m_cache_x_large, m_cache_b_large);
bob::math::linsolve( m_cache_A_large, m_cache_b_large, m_cache_x_large);
// 4) Find alpha and update x, lamda and mu
double alpha=1.;
......@@ -406,7 +406,7 @@ void bob::math::LPInteriorPointShortstep::solve(const blitz::Array<double,2>& A,
// 2) Update the big system and solve it
updateLargeSystem( x, sigma, m);
bob::math::linsolve( m_cache_A_large, m_cache_x_large, m_cache_b_large);
bob::math::linsolve( m_cache_A_large, m_cache_b_large, m_cache_x_large);
// 3) Update x, lamda and mu
m_lambda += m_cache_x_large( r_m+n);
......@@ -527,7 +527,7 @@ void bob::math::LPInteriorPointPredictorCorrector::solve(const blitz::Array<doub
// 2) Update the big system and solve it
updateLargeSystem( x, 0., m);
bob::math::linsolve( m_cache_A_large, m_cache_x_large, m_cache_b_large);
bob::math::linsolve( m_cache_A_large, m_cache_b_large, m_cache_x_large);
// 3) alpha=1
double alpha = 1.;
......@@ -560,7 +560,7 @@ void bob::math::LPInteriorPointPredictorCorrector::solve(const blitz::Array<doub
// 7) Update the big system and solve it
updateLargeSystem( x, 1., m);
bob::math::linsolve( m_cache_A_large, m_cache_x_large, m_cache_b_large);
bob::math::linsolve( m_cache_A_large, m_cache_b_large, m_cache_x_large);
// 8) Update x
m_lambda += m_cache_x_large(r_m+n);
......@@ -690,7 +690,7 @@ void bob::math::LPInteriorPointLongstep::solve(const blitz::Array<double,2>& A,
// 2) Update the big system and solve it
updateLargeSystem(x, m_sigma, m);
bob::math::linsolve(m_cache_A_large, m_cache_x_large, m_cache_b_large);
bob::math::linsolve(m_cache_A_large, m_cache_b_large, m_cache_x_large);
// 3) alpha=1
double alpha = 1.;
......@@ -737,4 +737,3 @@ void bob::math::LPInteriorPointLongstep::solve(const blitz::Array<double,2>& A,
// Launch the long step algorithm
solve(A, b, c, x, m_lambda, m_mu);
}
......@@ -22,8 +22,8 @@ extern "C" void dgesv_( const int *N, const int *NRHS, double *A,
extern "C" void dposv_( const char* uplo, const int *N, const int *NRHS,
double *A, const int *lda, double *B, const int *ldb, int *info);
void bob::math::linsolve(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b)
void bob::math::linsolve(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x)
{
// Check x and b
bob::core::array::assertZeroBase(x);
......@@ -35,11 +35,11 @@ void bob::math::linsolve(const blitz::Array<double,2>& A, blitz::Array<double,1>
bob::core::array::assertSameDimensionLength(A.extent(0), A.extent(1));
bob::core::array::assertSameDimensionLength(A.extent(1), b.extent(0));
bob::math::linsolve_(A, x, b);
bob::math::linsolve_(A, b, x);
}
void bob::math::linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b)
void bob::math::linsolve_(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x)
{
// Defines dimensionality variables
const int N = A.extent(0);
......@@ -82,8 +82,8 @@ void bob::math::linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,1
}
void bob::math::linsolve(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B)
void bob::math::linsolve(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X)
{
// Checks dimensionality and zero base
bob::core::array::assertZeroBase(A);
......@@ -94,12 +94,13 @@ void bob::math::linsolve(const blitz::Array<double,2>& A, blitz::Array<double,2>
bob::core::array::assertSameDimensionLength(A.extent(0), B.extent(0));
bob::core::array::assertSameDimensionLength(X.extent(1), B.extent(1));
bob::math::linsolve_(A, X, B);
bob::math::linsolve_(A, B, X);
}
void bob::math::linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B)
void bob::math::linsolve_(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X)
{
// Defines dimensionality variables
const int N = A.extent(0);
const int P = X.extent(1);
......@@ -148,7 +149,7 @@ void bob::math::linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,2
void bob::math::linsolveSympos(const blitz::Array<double,2>& A,
blitz::Array<double,1>& x, const blitz::Array<double,1>& b)
const blitz::Array<double,1>& b, blitz::Array<double,1>& x)
{
// Check x and b
bob::core::array::assertZeroBase(x);
......@@ -160,12 +161,13 @@ void bob::math::linsolveSympos(const blitz::Array<double,2>& A,
bob::core::array::assertSameDimensionLength(A.extent(0), A.extent(1));
bob::core::array::assertSameDimensionLength(A.extent(1), b.extent(0));
bob::math::linsolveSympos_(A, x, b);
bob::math::linsolveSympos_(A, b, x);
}
void bob::math::linsolveSympos_(const blitz::Array<double,2>& A,
blitz::Array<double,1>& x, const blitz::Array<double,1>& b)
const blitz::Array<double,1>& b, blitz::Array<double,1>& x)
{
// Defines dimensionality variables
const int N = A.extent(0);
......@@ -208,8 +210,8 @@ void bob::math::linsolveSympos_(const blitz::Array<double,2>& A,
x = x_blitz_lapack;
}
void bob::math::linsolveSympos(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B)
void bob::math::linsolveSympos(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X)
{
// Checks dimensionality and zero base
bob::core::array::assertZeroBase(A);
......@@ -220,11 +222,11 @@ void bob::math::linsolveSympos(const blitz::Array<double,2>& A, blitz::Array<dou
bob::core::array::assertSameDimensionLength(A.extent(0), B.extent(0));
bob::core::array::assertSameDimensionLength(X.extent(1), B.extent(1));
bob::math::linsolveSympos_(A, X, B);
bob::math::linsolveSympos_(A, B, X);
}
void bob::math::linsolveSympos_(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B)
void bob::math::linsolveSympos_(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X)
{
// Defines dimensionality variables
const int N = A.extent(0);
......@@ -275,8 +277,9 @@ void bob::math::linsolveSympos_(const blitz::Array<double,2>& A, blitz::Array<do
void bob::math::linsolveCGSympos(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b, const double acc, const int max_iter)
void bob::math::linsolveCGSympos(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x,
const double acc, const int max_iter)
{
// Dimensionality of the problem
const int N = b.extent(0);
......@@ -291,11 +294,12 @@ void bob::math::linsolveCGSympos(const blitz::Array<double,2>& A, blitz::Array<d
bob::core::array::assertSameDimensionLength(A.extent(0), N);
bob::core::array::assertSameDimensionLength(A.extent(1), N);
bob::math::linsolveCGSympos_(A, x, b, acc, max_iter);
bob::math::linsolveCGSympos_(A, b, x, acc, max_iter);
}
void bob::math::linsolveCGSympos_(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b, const double acc, const int max_iter)
void bob::math::linsolveCGSympos_(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x,
const double acc, const int max_iter)
{
// Dimensionality of the problem
const int N = b.extent(0);
......@@ -347,4 +351,3 @@ void bob::math::linsolveCGSympos_(const blitz::Array<double,2>& A, blitz::Array<
// TODO return best_res and number of iterations?
//double res = best_res;
}
......@@ -9,7 +9,7 @@
#define BOB_MATH_CONFIG_H
/* Macros that define versions and important names */
#define BOB_MATH_API_VERSION 0x0200
#define BOB_MATH_API_VERSION 0x0201
#ifdef BOB_IMPORT_VERSION
......
......@@ -23,10 +23,10 @@ namespace bob { namespace math {
* @param x The x vector of the system A*x=b which will be updated
* at the end of the function.
*/
void linsolve(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b);
void linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b);
void linsolve(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x);
void linsolve_(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x);
/**
* @brief Function which solves a linear system of equation using the
......@@ -36,10 +36,10 @@ namespace bob { namespace math {
* @param X The X matrix of the system A*X=B which will be updated
* at the end of the function (size NxP).
*/
void linsolve(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B);
void linsolve_(const blitz::Array<double,2>& A, blitz::Array<double,2>& X,
const blitz::Array<double,2>& B);
void linsolve(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X);
void linsolve_(const blitz::Array<double,2>& A,
const blitz::Array<double,2>& B, blitz::Array<double,2>& X);
/**
* @brief Function which solves a symmetric positive definite linear
......@@ -53,9 +53,9 @@ namespace bob { namespace math {
* at the end of the function (size N)
*/
void linsolveSympos(const blitz::Array<double,2>& A,
blitz::Array<double,1>& x, const blitz::Array<double,1>& b);
const blitz::Array<double,1>& b, blitz::Array<double,1>& x);
void linsolveSympos_(const blitz::Array<double,2>& A,
blitz::Array<double,1>& x, const blitz::Array<double,1>& b);
const blitz::Array<double,1>& b, blitz::Array<double,1>& x);
/**
* @brief Function which solves a symmetric positive definite linear
......@@ -69,9 +69,9 @@ namespace bob { namespace math {
* at the end of the function (size NxP)
*/
void linsolveSympos(const blitz::Array<double,2>& A,
blitz::Array<double,2>& X, const blitz::Array<double,2>& B);
const blitz::Array<double,2>& B, blitz::Array<double,2>& X);
void linsolveSympos_(const blitz::Array<double,2>& A,
blitz::Array<double,2>& X, const blitz::Array<double,2>& B);
const blitz::Array<double,2>& B, blitz::Array<double,2>& X);
/**
......@@ -86,12 +86,13 @@ namespace bob { namespace math {
* norm(Ax-b)/norm(b) < acc
* @param max_iter The maximum number of iterations
*/
void linsolveCGSympos(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b, const double acc, const int max_iter);
void linsolveCGSympos_(const blitz::Array<double,2>& A, blitz::Array<double,1>& x,
const blitz::Array<double,1>& b, const double acc, const int max_iter);
void linsolveCGSympos(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x,
const double acc, const int max_iter);
void linsolveCGSympos_(const blitz::Array<double,2>& A,
const blitz::Array<double,1>& b, blitz::Array<double,1>& x,
const double acc, const int max_iter);
}}
#endif /* BOB_MATH_LINSOLVE_H */
......@@ -12,21 +12,38 @@
#include <bob.blitz/cppapi.h>
#include <bob.blitz/cleanup.h>
#include <bob.math/linsolve.h>
#include <bob.extension/documentation.h>
bob::extension::FunctionDoc s_linsolve = bob::extension::FunctionDoc(
"linsolve",
"Solves the linear system :math:`Ax=b` and returns the result in :math:`x`.",
"This method uses LAPACK's ``dgesv`` generic solver. "
"You can use this method in two different formats. "
"The first interface accepts the matrices :math:`A` and :math:`b` returning :math:`x`. "
"The second one accepts a pre-allocated :math:`x` vector and sets it with the linear system solution."
)
.add_prototype("A, b", "x")
.add_prototype("A, b, x")
.add_parameter("A", "array_like (2D)", "The matrix :math:`A` of the linear system")
.add_parameter("b", "array_like (1D)", "The vector :math:`b` of the linear system")
.add_parameter("x", "array_like (1D)", "The result vector :math:`x`, as parameter")
.add_return("x", "array_like (1D)", "The result vector :math:`x`, as return value")
;
static PyObject* py_linsolve_1(PyObject*, PyObject* args, PyObject* kwds) {
BOB_TRY
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "A", "x", "b", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
char** kwlist = s_linsolve.kwlist(1);
PyBlitzArrayObject* A = 0;
PyBlitzArrayObject* x = 0;
PyBlitzArrayObject* b = 0;
PyBlitzArrayObject* x = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&", kwlist,
&PyBlitzArray_Converter, &A,
&PyBlitzArray_OutputConverter, &x,
&PyBlitzArray_Converter, &b
&PyBlitzArray_Converter, &b,
&PyBlitzArray_OutputConverter, &x
)) return 0;
......@@ -52,49 +69,37 @@ static PyObject* py_linsolve_1(PyObject*, PyObject* args, PyObject* kwds) {
return 0;
}
try {
switch(b->ndim) {
case 1:
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(x),
*PyBlitzArrayCxx_AsBlitz<double,1>(b)
);
break;
case 2:
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(x),
*PyBlitzArrayCxx_AsBlitz<double,2>(b)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D problems, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
switch(b->ndim) {
case 1:
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(b),
*PyBlitzArrayCxx_AsBlitz<double,1>(x)
);
break;
case 2:
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(b),
*PyBlitzArrayCxx_AsBlitz<double,2>(x)
);
break;
}
catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
catch (...) {
PyErr_SetString(PyExc_RuntimeError, "linsolve failed: unknown exception caught");
return 0;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D problems, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
Py_RETURN_NONE;
BOB_CATCH_FUNCTION("linsolve", 0)
}
static PyObject* py_linsolve_2(PyObject*, PyObject* args, PyObject* kwds) {
BOB_TRY
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "A", "b", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
char** kwlist = s_linsolve.kwlist(0);
PyBlitzArrayObject* A = 0;
PyBlitzArrayObject* b = 0;
......@@ -118,51 +123,40 @@ static PyObject* py_linsolve_2(PyObject*, PyObject* args, PyObject* kwds) {
return 0;
}
PyObject* retval = 0;
try {
switch(b->ndim) {
case 1:
retval = PyBlitzArray_SimpleNew(NPY_FLOAT64, b->ndim, b->shape);
if (!retval) return 0;
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>((PyBlitzArrayObject*)retval),
*PyBlitzArrayCxx_AsBlitz<double,1>(b)
);
break;
case 2:
retval = PyBlitzArray_SimpleNew(NPY_FLOAT64, b->ndim, b->shape);
if (!retval) return 0;
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>((PyBlitzArrayObject*)retval),
*PyBlitzArrayCxx_AsBlitz<double,2>(b)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D arrays, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
PyBlitzArrayObject* retval = 0;
auto retval_ = make_xsafe(retval);
}
catch (std::exception& e) {
Py_DECREF(retval);
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
catch (...) {
Py_DECREF(retval);
PyErr_SetString(PyExc_RuntimeError, "linsolve failed: unknown exception caught");
return 0;
switch(b->ndim) {
case 1:
retval = (PyBlitzArrayObject*)PyBlitzArray_SimpleNew(NPY_FLOAT64, b->ndim, b->shape);
if (!retval) return 0;
retval_ = make_safe(retval);
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(b),
*PyBlitzArrayCxx_AsBlitz<double,1>(retval)
);
break;
case 2:
retval = (PyBlitzArrayObject*)PyBlitzArray_SimpleNew(NPY_FLOAT64, b->ndim, b->shape);
if (!retval) return 0;
retval_ = make_safe(retval);
bob::math::linsolve(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(b),
*PyBlitzArrayCxx_AsBlitz<double,2>(retval)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D arrays, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
return PyBlitzArray_NUMPY_WRAP(retval);
return PyBlitzArray_AsNumpyArray(retval, 0);
BOB_CATCH_FUNCTION("linsolve", 0)
}
/**
......@@ -172,113 +166,52 @@ PyObject* py_linsolve(PyObject*, PyObject* args, PyObject* kwargs) {
Py_ssize_t nargs = args?PyTuple_Size(args):0 + kwargs?PyDict_Size(kwargs):0;
PyObject* retval = 0;
switch (nargs) {
case 3:
retval = py_linsolve_1(0, args, kwargs);
break;
return py_linsolve_1(0, args, kwargs);
case 2:
retval = py_linsolve_2(0, args, kwargs);
break;
return py_linsolve_2(0, args, kwargs);
default:
PyErr_Format(PyExc_RuntimeError, "number of arguments mismatch - linsolve requires 2 or 3 arguments, but you provided %" PY_FORMAT_SIZE_T "d (see help)", nargs);
}
return retval;
return 0;
}
PyObject* py_linsolve_nocheck(PyObject*, PyObject* args, PyObject* kwds) {
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "A", "x", "b", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
PyBlitzArrayObject* A = 0;
PyBlitzArrayObject* x = 0;
PyBlitzArrayObject* b = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&", kwlist,
&PyBlitzArray_Converter, &A,
&PyBlitzArray_OutputConverter, &x,
&PyBlitzArray_Converter, &b
)) return 0;
bob::extension::FunctionDoc s_linsolve_sympos = bob::extension::FunctionDoc(
"linsolve_sympos",
"Solves the linear system :math:`Ax=b` and returns the result in :math:`x` for symmetric :math:`A` matrix.",
"This method uses LAPACK's ``dposv`` solver, assuming :math:`A` is a symmetric positive definite matrix. "
"You can use this method in two different formats. "
"The first interface accepts the matrices :math:`A` and :math:`b` returning :math:`x`. "
"The second one accepts a pre-allocated :math:`x` vector and sets it with the linear system solution."
)
.add_prototype("A, b", "x")
.add_prototype("A, b, x")
.add_parameter("A", "array_like (2D)", "The matrix :math:`A` of the linear system")
.add_parameter("b", "array_like (1D)", "The vector :math:`b` of the linear system")
.add_parameter("x", "array_like (1D)", "The result vector :math:`x`, as parameter")
.add_return("x", "array_like (1D)", "The result vector :math:`x`, as return value")
;
//protects acquired resources through this scope
auto A_ = make_safe(A);
auto x_ = make_safe(x);
auto b_ = make_safe(b);
if (A->type_num != NPY_FLOAT64 ||
x->type_num != NPY_FLOAT64 ||
b->type_num != NPY_FLOAT64) {
PyErr_Format(PyExc_TypeError, "linear solver only supports float type (i.e., `numpy.float64' equivalents) - make sure all your input conforms");
return 0;
}
if (A->ndim != x->ndim || A->ndim != b->ndim) {
PyErr_Format(PyExc_TypeError, "mismatch between the number of dimensions of A, x and b (respectively %" PY_FORMAT_SIZE_T "d, %" PY_FORMAT_SIZE_T "d and %" PY_FORMAT_SIZE_T "d) - all input must have the same number of dimensions", A->ndim, x->ndim, b->ndim);
return 0;
}
try {
switch(b->ndim) {
case 1:
bob::math::linsolve_(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(x),
*PyBlitzArrayCxx_AsBlitz<double,1>(b)
);
break;
case 2:
bob::math::linsolve_(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(x),
*PyBlitzArrayCxx_AsBlitz<double,2>(b)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D arrays, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
}
catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
catch (...) {
PyErr_SetString(PyExc_RuntimeError, "linsolve_ failed: unknown exception caught");
return 0;
}
Py_RETURN_NONE;
}
static PyObject* py_linsolve_sympos_1(PyObject*, PyObject* args, PyObject* kwds) {
BOB_TRY
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "A", "x", "b", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
char** kwlist = s_linsolve_sympos.kwlist(1);
PyBlitzArrayObject* A = 0;
PyBlitzArrayObject* x = 0;
PyBlitzArrayObject* b = 0;
PyBlitzArrayObject* x = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&", kwlist,
&PyBlitzArray_Converter, &A,
&PyBlitzArray_OutputConverter, &x,
&PyBlitzArray_Converter, &b
&PyBlitzArray_Converter, &b,
&PyBlitzArray_OutputConverter, &x
)) return 0;
//protects acquired resources through this scope
......@@ -303,49 +236,36 @@ static PyObject* py_linsolve_sympos_1(PyObject*, PyObject* args, PyObject* kwds)
return 0;
}
try {
switch(b->ndim) {
case 1:
bob::math::linsolveSympos(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(x),
*PyBlitzArrayCxx_AsBlitz<double,1>(b)
);
break;
case 2:
bob::math::linsolveSympos(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(x),
*PyBlitzArrayCxx_AsBlitz<double,2>(b)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D problems, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
switch(b->ndim) {
case 1:
bob::math::linsolveSympos(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,1>(b),
*PyBlitzArrayCxx_AsBlitz<double,1>(x)
);
break;
}
catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
catch (...) {
PyErr_SetString(PyExc_RuntimeError, "linsolve_sympos failed: unknown exception caught");
return 0;
case 2:
bob::math::linsolveSympos(
*PyBlitzArrayCxx_AsBlitz<double,2>(A),
*PyBlitzArrayCxx_AsBlitz<double,2>(b),
*PyBlitzArrayCxx_AsBlitz<double,2>(x)
);
break;
default:
PyErr_Format(PyExc_TypeError, "linear solver can only work with 1D or 2D problems, but your b array has %" PY_FORMAT_SIZE_T "d dimensions", b->ndim);
return 0;
}
Py_RETURN_NONE;
BOB_CATCH_FUNCTION("linsolve_sympos", 0)
}
static PyObject* py_linsolve_sympos_2(PyObject*, PyObject* args, PyObject* kwds) {
BOB_TRY
/* Parses input arguments in a single shot */
static const char* const_kwlist[] = { "A", "b", 0 /* Sentinel */ };
static char** kwlist = const_cast<char**>(const_kwlist);
char** kwlist = s_linsolve_sympos.kwlist(0);
PyBlitzArrayObject* A = 0;
PyBlitzArrayObject* b = 0;
......@@ -369,50 +289,38 @@ static PyObject* py_linsolve_sympos_2(PyObject*, PyObject* args, PyObject* kwds)
return 0;
}
PyObject* retval = 0;
try {
PyBlitzArrayObject* retval = 0;
auto retval_ = make_xsafe(retval);