3

I need to use lapack function 'DGGLSE' in python to solve a least square problem with constraints.

I found some low level functions of lapack can be found in scipy as follow http://docs.scipy.org/doc/scipy/reference/linalg.lapack.html but the one I am interested was not included, and seems that most of driver codes of lapack is not included anyway.

I wonder if there is way I can do it. Thanks. -Yan

ywang
  • 101
  • 3
  • 8
  • have a look [at this answer](http://stackoverflow.com/a/16153914/832621), where it is explained how to wrap DGEMM with Cython, you can probably do a similar approach to use DDGLSE... – Saullo G. P. Castro Aug 13 '13 at 08:31

2 Answers2

2

I only have a little experience wrapping Fortran, but as I understand it, the standard way to wrap LAPACK functions that aren't already included in SciPy is to use the tool f2py that is included with NumPy. Some basic instructions can be found at http://wiki.scipy.org/Cookbook/F2Py#head-9c22e0d6fa6b16650feea2c271233a8c47e8d051

You can also wrap it through Cython. Doing it that way, you compile the Fortran file and link against it as shown at http://fortran90.org/src/best-practices.html#interfacing-with-python There it describes how to use either Cython or ctypes to wrap a Fortran subroutine. That particular example is available online at https://github.com/certik/fortran90_question/tree/master/fcython_mesh Make sure you pay attention to how your array is arranged in memory (C-contiguous vs. Fortran-contiguous).

IanH
  • 10,250
  • 1
  • 28
  • 32
0

?GGLSE routine family is included with the SciPy version 1.0. You can first call ?gglse_lwork to get the optimal block size on your hardware and then use it as an argument to ?gglse.

You can check the signature on ipython console via

scipy.linalg.lapack.dgglse?

or using help and so on.

percusse
  • 3,006
  • 1
  • 14
  • 28