[SciPy-Dev] scipy.sparse spdiags/dia_matrix additional calling mode
Thu Oct 6 08:10:41 CDT 2011
At first I thought that example would fail since the row(s) did not have
but then I realised that there are actually no checks at all on the size of
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
There, the equivalent expression spdiags([[1,2,3]'], 1, 4, 4) gives an index
(also strange kind of error). With the offset -1 it works fine, though, and
if I add elements to the diagonal so that it has length 4. So somewhat
but the scipy implementation does not seem to be fully equivalent to the
Still, the change I suggested would probably have to raise an exception if
list has diagonals of the wrong length, and this would still break more
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
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'?
On Thu, Oct 6, 2011 at 2:30 PM, Pauli Virtanen <firstname.lastname@example.org> wrote:
> 06.10.2011 11:33, Pauli Virtanen kirjoitti:
> >> 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]], , 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-Dev