[SciPy-dev] band matrix wrapping ready for inclusion

Nils Wagner nwagner at iam.uni-stuttgart.de
Fri Jun 30 09:07:01 EDT 2006


Arnd Baecker wrote:
> On Fri, 30 Jun 2006, Nils Wagner wrote:
>
>   
>> Arnd Baecker wrote:
>>     
>>> On Thu, 29 Jun 2006, Travis Oliphant wrote:
>>>
>>>
>>>       
>>>> Arnd Baecker wrote:
>>>>
>>>>         
>>>>> Hi,
>>>>>
>>>>> sorry for asking again, but I would really be happy
>>>>> to get this finished...
>>>>>
>>>>> Travis, Robert or Pearu: may I go ahead with integrating
>>>>> the band matrix wrappers into scipy svn?
>>>>>
>>>>>
>>>>>           
>>>> I say go ahead.  It looks like an additional feature with a reasonable
>>>> interface that should not affect other code.
>>>>
>>>>         
>>> Many thanks, code is commited. All tests pass without problems.
>>>
>>> Best, Arnd
>>> _______________________________________________
>>> Scipy-dev mailing list
>>> Scipy-dev at scipy.org
>>> http://projects.scipy.org/mailman/listinfo/scipy-dev
>>>
>>>       
>>  Hi Arnd,
>>
>> Thank you very much for the support of band matrices in scipy. That is
>> very useful.
>> BTW, is it possible to convert full matrices to band matrices and vice
>> versa ?
>>     
>
> Yes.
> For an example of the conversion of a full matrix to band
> see Lib/linalg/tests/test_decomp.py
> where you find code blocks like
>
>         # Extract upper bands from symmetric and hermitian band matrices
>         # (for use in dsbevd, dsbevx, zhbevd, zhbevx
>         #  and their single precision versions)
>         LDAB = self.KU + 1
>         self.bandmat_sym  = zeros((LDAB, N), dtype=float)
>         self.bandmat_herm = zeros((LDAB, N), dtype=complex)
>         for i in xrange(LDAB):
>             self.bandmat_sym[LDAB-i-1,i:N]  = diag(self.sym_mat, i)
>             self.bandmat_herm[LDAB-i-1,i:N] = diag(self.herm_mat, i)
>
> HTH,
>
> Arnd
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev
>   
Did you check general band matrices ?

If you need a test for real nonsymmetric band matrices

from scipy import linalg, diag, arange, linspace, sort
def sylvester(n):
#
#  Sylvester matrix
#
   tmp = diag(arange(1,n),1)+diag(arange(n-1,0,-1),-1)
   return tmp

n = 9
A = sylvester(n)
w1=linalg.eigvals(A)
w1=sort(w1.real)
#
# Exact eigenvalues
#
w_ex = linspace(-(n-1),n-1,n,endpoint=True)
print linalg.norm(w1-w_ex)

Nils




More information about the SciPy-Dev mailing list