Closed KristofferC closed 9 years ago
Yes, we can get rid of the ones in csparse.jl. Could you submit a PR?
Yeah, one problem is that there is no corresponding triu!
in linalg.jl
which means that after removing triu!
from csparse.jl
Julia falls back to the dense implementation. I could of course only remove the non mutating version but it feels better to see if the linalg.jl
one could easily be modified to be mutating and then add non mutating methods in the usual way.
Odd that they differ by so much. fkeep!
is fairly generic and it's using a functor at least for the k=0
case so I'm a little surprised to see so much performance difference. fkeep!
could potentially be made competitive with some manual hoisting of the field accesses out of the loops.
Yeah, I will experiment a bit.
The reason for fkeep!
being slower is that it copies the whole matrix in its non mutating function. The one in linalg.jl
doesn't construct the arrays until it knows how many non zero values will exist in the final matrix.
Maybe just drop the non-mutating copy version from csparse.jl
then. Hoisting may help with the mutating version.
Yeah, hoisting + @inbounds
is about a 30-40% speedup. I noticed that tril!(A, k)
where k
is an integer currently falls back to the dense version which of course never finishes. What should be done about that?
Could try extending TriuFun
and TrilFun
to include a k
offset field? Though I suspect the same conclusions will hold where tril!(copy(A), k)
would end up slower than a tril(A, k)
that only allocates what it needs.
There are currently two
triu
andtril
methods for sparse matrices. One incsparse.jl
here and one inlinalg.jl
hereThe latter one supports setting a diagonal offset
k
but fork=0
the methods should be the same. Now timing these:means that the
triu
incsparse.jl
(which is the default one and the one everyone is likely using) is slower (at least for this random matrix I tried, not sure how it varies with different sparse structure).Doesn't it make sense to delete
triu
incsparse.jl
and setting a defaultk=0
on the one inlinalg.jl
? Same fortril
.