[SciPy-Dev] linalg.toeplitz and ticker #667

josef.pktd@gmai... josef.pktd@gmai...
Sun Mar 7 20:05:47 CST 2010

On Sun, Mar 7, 2010 at 8:32 PM, Warren Weckesser
<warren.weckesser@enthought.com> wrote:
> Warren Weckesser wrote:
>> I am going to update linalg.toeplitz to fix the problem reported in
>> ticket #667, but I have some questions about the desired behavior of
>> the function when either `c` (the first column) or `r` (the first row)
>> is complex.  The docstring does not say anything about complex values,
>> but the code does some undocumented and unexpected things in this
>> case, one example of which is the bug reported in the ticket #667.
>> I would like to fix this, but I would first like opinions on exactly
>> how it *should* handle complex arguments.  I *think* the idea is that
>> if `c` is complex and `r` is not given, then a Hermitian Toeplitz
>> matrix is created.  Is that correct?  Note that this requires that
>> c[0] be real, since c[0] is the value that will be in the diagonal of
>> the matrix.
>> While I am fixing this, I would like to remove the printed warning
>> that occurs when r[0] != c[0].  I would like to change this to raise
>> a ValueError--that is, adopt the philosophy that either the arguments
>> are correct (and the code handles them as [not yet, but soon to be]
>> documented in the docstring, with no warnings needed), or the
>> arguments are wrong and an exception should be raised.
>> This means that when `r` is not given, an exception would be raised
>> if c[0] is not real.
>> A very different way to handle the case of `r` not being given is to
>> assume it means a square matrix should be created with r[1:] = 0
>> (i.e. zeros in all the upper off-diagonals).  This avoids the whole
>> issue of complex numbers and conjugates, but it is also a more
>> drastic change.

a lot of code relies on toeplitz of a single argument to build the
symmetric matrix.

> By the way, that is how linalg.hankel handles the case where `r` is not
> given.


>>> import scipy.linalg
>>> scipy.linalg.toeplitz(np.arange(4))
array([[0, 1, 2, 3],
       [1, 0, 1, 2],
       [2, 1, 0, 1],
       [3, 2, 1, 0]])
>>> scipy.linalg.hankel(np.arange(4))
array([[ 0.,  1.,  2.,  3.],
       [ 1.,  2.,  3.,  0.],
       [ 2.,  3.,  0.,  0.],
       [ 3.,  0.,  0.,  0.]])
>>> scipy.linalg.hankel(np.arange(4)+1.j)
array([[ 0.+1.j,  1.+1.j,  2.+1.j,  3.+1.j],
       [ 1.+1.j,  2.+1.j,  3.+1.j,  0.+0.j],
       [ 2.+1.j,  3.+1.j,  0.+0.j,  0.+0.j],
       [ 3.+1.j,  0.+0.j,  0.+0.j,  0.+0.j]])
>>> scipy.linalg.toeplitz(np.arange(4)+1.j)
Warning: column and row values don't agree; column value used.
array([[ 0.+1.j,  1.+1.j,  2.+1.j,  3.+1.j],
       [ 1.-1.j,  0.+1.j,  1.+1.j,  2.+1.j],
       [ 2.-1.j,  1.-1.j,  0.+1.j,  1.+1.j],
       [ 3.-1.j,  2.-1.j,  1.-1.j,  0.+1.j]])

requiring the diagonal to be real might be too tough, I'm not using
complex toeplitz, but for other cases, I often have "almost real"
values, up to numerical imprecision.

>>> scipy.linalg.toeplitz(np.arange(4)*1.j,-np.arange(4)*1.j)
array([[ 0.+0.j,  0.-1.j,  0.-2.j,  0.-3.j],
       [ 0.+1.j,  0.+0.j,  0.-1.j,  0.-2.j],
       [ 0.+2.j,  0.+1.j,  0.+0.j,  0.-1.j],
       [ 0.+3.j,  0.+2.j,  0.+1.j,  0.+0.j]])

also for real values  r[0] != c[0] might not be satisfied if there is
numerical imprecision and they are only almost equal.


> Warren
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev

More information about the SciPy-Dev mailing list