I actually started out with having two separate functions, but merging them made sense to me, since there is more shared code than unique-per-branch. I also thought it would be nicer for client-code since there is no more need to care whether you have CSR or CSC matrices on your hand. You are of course right that it adds more Cython-code that needs to be there, but I think it's worth the trade-off. This way, if someone is ever going to do add this functionality for other sparse formats, there's only one place to look/edit instead of two.  Adding a separate dispatch- and error-checking function would in this case also mean adding an entirely new Python file (which I'm not sure how to name, but I'm open for suggestions).