sparsemat / sprs

sparse linear algebra library for rust
Apache License 2.0
386 stars 45 forks source link

Add to_inner_onehot, into_csc, and into_csr #191

Closed austinjones closed 4 years ago

austinjones commented 4 years ago

Hey @vbarrielle, As in #190, here is an implementation of 'to_inner_onehot'.

I thought about writing 'to_row_onehot' and 'to_column_onehot', because users would probably want to onehot along a specific direction, but settled on adding 'into_csc' and 'into_csr', which cheaply return self if the CSC/CSR compression type is correct. They can only be called on an owned CsMatBase with Vec storage, as the return type between the branches needs to be equal. Users can chain them: mat.into_csr().to_inner_onehot()

Also, the where bound could be lowered to N: Num if to_inner_onehot panicked on NaNs. Right now it requires N: Float so that NaNs can be filtered out before the max_by.

Let me know if you have any comments.

vbarrielle commented 4 years ago

This is neat, thanks! I do agree it's good to chain using mat.into_csr().to_inner_onehot(). Restricting to N: Float seems reasonable as well, if eg integers are later needed it should be possible to extend the API.