wo80 / CSparse.NET

A concise library for solving sparse linear systems with direct methods.
GNU Lesser General Public License v2.1
58 stars 25 forks source link

Add ValueTuple overload for creating CompressedColumnStorage #46

Closed miniksa closed 4 months ago

miniksa commented 4 months ago

When working with this package, I wanted to use ValueTuple over classic Tuple to avoid the heap allocation that occurs on every single Tuple (improving performance).

miniksa commented 4 months ago

If you want me to add more overloads elsewhere or otherwise deduplicate this somehow... let me know. I intentionally tried to keep this scoped as narrow as possible until hearing from you.

miniksa commented 4 months ago

@Austin-Lamb, my co-worker, suggests that I should use names on the parts of the ValueTuple so it's less ugly than Item1, Item2, etc.

wo80 commented 4 months ago

Thanks!

The method parameters should also be documented in the public CompressedColumnStorage class.

Leaving the original conversion method for enumerables of Tuple in place is fine.

I was wondering whether the IEnumerable<Tuple<int, int, T>> EnumerateIndexed() method of the Matrix class should also use ValueTuple. What do you think? It affects the public API, but the change is small, so maybe no need to increment the major version.

https://github.com/wo80/CSparse.NET/blob/5547c20e70ba930001bb690b6b59885eebe26c7e/CSparse/Matrix.cs#L132-L136

miniksa commented 4 months ago

Thanks!

The method parameters should also be documented in the public CompressedColumnStorage class.

Leaving the original conversion method for enumerables of Tuple in place is fine.

I was wondering whether the IEnumerable<Tuple<int, int, T>> EnumerateIndexed() method of the Matrix class should also use ValueTuple. What do you think? It affects the public API, but the change is small, so maybe no need to increment the major version.

https://github.com/wo80/CSparse.NET/blob/5547c20e70ba930001bb690b6b59885eebe26c7e/CSparse/Matrix.cs#L132-L136

Yeah I thought about that, but I didn't want to change the public API. I almost thought of making EnumerateIndexedAsValueTuples() or something just to not break anyone.... but that depends what you prefer.

I know that it would increase the performance for when it's used in the FromMatrix() method and I could link that up without all those temporary allocations.

miniksa commented 4 months ago

Try this on, @wo80. I made a separate abstract method and implemented that one in both the Compressed and Dense matrix classes, then used it in the .OfMatrix helper. Happy to keep iterating if you want me to just replace the old one. I'm just normally allergic to public API breaking changes.

wo80 commented 4 months ago

I'm just normally allergic to public API breaking changes.

I fully agree. Version 4 was just published, and I don't want to release a new major version with such a minor change, so let's leave it this way.

I'll add a TODO comment to replace the old method and hopefully will remember when version 5 is released ... in 10 years or so 😁