[SciPy-dev] Refactoring of csc/csr sparse matrices

Nathan Bell wnbell at gmail.com
Thu Jan 11 01:02:42 EST 2007


On 1/10/07, Tim Leslie <tim.leslie at gmail.com> wrote:
> The problem is that changing these names would break the current
> interface. This could be un-broken by using __getattr__/__setattr__ to
> trap all calls to rowind/colind and pass them on to 'indices'.
>
> So, the question is should we a) make no change, b) make the change
> and change the interface or c) make the change but keep the old
> interface. I'm personally in favour or c), but I'd like to hear what
> other people have to say.

Option C is fine with me.  Should deprecation warning be printed if
rowind/colind is used?



Also, in your current code you have things like:
487 	    def __add__(self, other, self_ind, other_ind, fn, cls):
<snip>
493 	        elif isspmatrix(other):
494 	            other = other.tocsc()
495 	            if (other.shape != self.shape):
496 	                raise ValueError, "inconsistent shapes"
497 	            if other_ind:
498 	                other = other.tocsc()
499 	                other_ind = other.rowind
500 	            else:
501 	                other = other.tocsr()
502 	                other_ind = other.colind


With the change to .indices, a somewhat better/more efficient approach would be:

487 	    def __add__(self, other, self_ind, other_ind, fn, cls):
<snip>
493 	        elif isspmatrix(other):
494 	            other = cls(other)
495 	            if (other.shape != self.shape):
496 	                raise ValueError, "inconsistent shapes"

The constructor of cls should do the proper conversion (if necessary)
for you.  With this, I believe self_ind and other_ind become
unnecessary.

Thanks for refactoring those classes, maintaining them separately was
a bit tedious :)

-- 
Nathan Bell wnbell at gmail.com



More information about the SciPy-Dev mailing list