[SciPy-Dev] scipy.sparse spdiags/dia_matrix additional calling mode
Tony Stillfjord
tony@maths.lth...
Thu Oct 6 08:10:41 CDT 2011
At first I thought that example would fail since the row(s) did not have
length 4,
but then I realised that there are actually no checks at all on the size of
the
diagonals, just that the number of them correspond to the number of offsets
and that there are no duplicates...
I tried it in MATLAB too just to check if this behaviour really is that
strange.
There, the equivalent expression spdiags([[1,2,3]'], 1, 4, 4) gives an index
error
(also strange kind of error). With the offset -1 it works fine, though, and
also
if I add elements to the diagonal so that it has length 4. So somewhat
strange,
but the scipy implementation does not seem to be fully equivalent to the
MATLAB
one.
Still, the change I suggested would probably have to raise an exception if
the
list has diagonals of the wrong length, and this would still break more
'normal'
constructions like my original example,
spdiags([ones(4), -2*ones(4), ones(4)], (-1,0,1), 4, 4),
so I agree that this shouldn't be done.
I'm more in favour of a keyword flag rather than a new function. spdiags
feels
like the accepted name for what is to be done, and then how to do it more
specifically should be an option within this framework (function). Maybe
'padding = False/True' or 'exact_length = False/True'?
Regards,
Tony Stillfjord
On Thu, Oct 6, 2011 at 2:30 PM, Pauli Virtanen <pav@iki.fi> wrote:
> 06.10.2011 11:33, Pauli Virtanen kirjoitti:
> [clip]
> >> Currently, the first input has to be an array 'data' where every row
> >> corresponds to a diagonal - which one is specified in the next input,
> 'diags'. However,
> >> as the diagonals have different length, the actual values have to be
> zero-padded on
> >> either the left or right end to fit the array.
> > [clip]
> >
> > I was just thinking about the same thing: the way it works now is a bit
> > of a pain.
>
> After a moment of thought, I believe the semantics of `spdiags` cannot
> be changed without also affecting the meaning of:
>
> sparse.spdiags([[1,2,3]], [1], 4, 4)
>
> The remaining options are either to add a keyword flag to the function,
> or to add a separate function (maybe called `diags` or something) to
> toggle the more convenient offset semantics.
>
> --
> Pauli Virtanen
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20111006/dc8bae4b/attachment.html
More information about the SciPy-Dev
mailing list