[Numpy-discussion] how to use lu decomposition in lapack library?

Piotr Luszczek luszczek at cs.utk.edu
Tue Oct 4 12:41:04 CDT 2005


Then you have to dig in deeper:

import numarray
import numarray.linear_algebra
import numarray.linear_algebra.lapack_lite2 as lapack_lite

piv = numarray.zeros((n,), "l")
outcome = lapack_lite.dgesv(n, nrhs, a, lda, piv, b, ldb, 0)

outcome['info'] is the 'info' parameter set by LAPACK.

You have to make sure that 'a' and 'b' are in Fortran order
because you're calling Fortran code. Here is a sample code:

>>> a=numarray.array([[1,2,3],[4,5,6]], 'd')
>>> a.is_fortran_contiguous()
0
>>> a.is_c_array()
True
>>> a.is_f_array()
0
>>> a.transpose()
>>> a.is_fortran_contiguous()
1
>>> a.is_c_array()
False
>>> a.is_f_array()
True

Call to 'transpose()' made it a Fortran array but it transposed
the array too.

Piotr

meng at are.berkeley.edu wrote:
> Thanks, Piotr!
> 
> What I actually want is the lower (L) and upper triangular matrix (U) 
> from matrix 'a'. How to get it?
> 
> Xiangyi
> 
> At 15:14 2005-10-4 -0400, you wrote:
> 
>> You would have to be more specific. If you just want to
>> solve a system of linear equations with matrix 'a' and
>> right-hand-side 'b':
>>
>> import numarray.linear_algebra as LA
>>
>> x = LA.solve_linear_equations(a, b)
>>
>> Unlike LAPACK, the above will leave your 'a' untouched.
>> So, if you have another right hand side 'b1' and the
>> same matrix 'a' you'll have to pay the cost of factorization
>> all over again.
>>
>> There is a way around it but I don't know what you really need.
>>
>> Piotr
>>
>> meng at are.berkeley.edu wrote:
>>
>>> Hi there-
>>> Can someone help me on this? Thanks!
>>> Best,
>>> Xiangyi
>>> Xiangyi Meng
>>> Department of Agricultural and Resource Economics
>>> Room 303, Giannini Hall #3310
>>> University of California, Berkeley
>>> Berkeley, CA 94720-3310
>>> Tel:  (510) 643-4124
>>> Fax: (510) 643-8911
>>> Email: meng at are.berkeley.edu
>>>
>>>
>>> -------------------------------------------------------
>>> This SF.Net email is sponsored by:
>>> Power Architecture Resource Center: Free content, downloads, 
>>> discussions,
>>> and more. http://solutions.newsforge.com/ibmarch.tmpl
>>> _______________________________________________
>>> Numpy-discussion mailing list
>>> Numpy-discussion at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
> 
> 
> Best,
> Xiangyi
> 
> Xiangyi Meng
> Department of Agricultural and Resource Economics
> Room 303, Giannini Hall #3310
> University of California, Berkeley
> Berkeley, CA 94720-3310
> Tel:  (510) 643-4124
> Fax: (510) 643-8911
> Email: meng at are.berkeley.edu
>          






More information about the Numpy-discussion mailing list